我想编写一个调用 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 strip (GNU Binutils for Ubuntu) 2.21.53.20110810 - Mac OS 上的 strip X 10.6 雪豹