【发布时间】:2011-10-17 00:55:19
【问题描述】:
我想编写一个从
调用 mvndst_() 子例程的 C++ 程序http://www.math.wsu.edu/faculty/genz/software/fort77/mvndstpack.f
在 Linux 上,如果我创建 test.cc:
extern "C" {
int mvndst_(int *, double *, double *, int *, double *, int *,
double *, double *, double *, double *, int *);
};
int main() {
return 0;
}
并通过编译
g++ -c -o test.o test.cc
gfortran -c -o mvndstpack.o mvndstpack.f
gfortran -Mnomain -o test test.o mvndstpack.o
然后我得到
mvndstpack.o: In function `main':
mvndstpack.f:(.text+0x4a2a): multiple definition of `main'
test.o:test.cc:(.text+0x0): first defined here
collect2: ld returned 1 exit status
但是,如果我在链接之前运行strip -N main mvndstpack.o,则链接成功。有人可以解释为什么 -Mnomain 标志在这里不起作用吗?我还想避免使用“strip”的解决方案,因为 Mac OS X 上“strip”的行为似乎不同(即 -N 选项不可用,我不确定另一种方法获得正确的行为)。如果可能的话,我还想避免编辑原始的 Fortran 源代码。
详情: - GNU Fortran (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1 - g++ (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1 - GNU 条(用于 Ubuntu 的 GNU Binutils)2.21.53.20110810 - 在 Mac OS X 10.6 Snow Leopard 上剥离
【问题讨论】: