VC调用Fortran的DLL!!着急!!

yheysj 2010-04-04 09:04:52
fortran 源码如下:
! ggg.f90
!
! FUNCTIONS/SUBROUTINES exported from ggg.dll:
! ggg - subroutine
!
subroutine ggg(v1,v2,r)
implicit none
! Expose subroutine ggg to users of this DLL
!
!DEC$ ATTRIBUTES DLLEXPORT::ggg

! Variables
real v1,v2,r
r=sqrt(v1*v1+v2*v2)
! Body of ggg

end subroutine ggg
建立一个win32有hello world 输出:
源代码如下:
//

#include "stdafx.h"
extern "C" void ggg(float v1,float v2,float &r);
extern "C" _declspec(dllexport)
void _stdcall C_Callfor(float a,float b,float &c)
{
ggg(a,b,c);
}
int main(int argc, char* argv[])
{
float a,b,c;
a=3.0;
b=4.0;
C_Callfor(a,b,&c);
printf("Hello World!\n");
return 0;
}

此过程我已经将ggg.lib 和ggg.dll加载到当前工程!!
编译Vc不通过,如下:
--------------------Configuration: cpp - Win32 Debug--------------------
Compiling...
cpp.cpp
Linking...
Creating library Debug/cpp.lib and object Debug/cpp.exp
cpp.obj : error LNK2001: unresolved external symbol _ggg
Debug/cpp.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

cpp.exe - 2 error(s), 0 warning(s)


求求求!!
...全文
139 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
gules 2010-11-22
  • 打赏
  • 举报
回复
实际上我不懂楼主的问题,我只是对
C_Callfor(a,b,&c); // &c 的类型不是 float* 吗?而函数声明与定义的类型是 float& 引用啊!
这一句居然能编译通过表示惊讶!
yheysj 2010-11-22
  • 打赏
  • 举报
回复
还有没有其他的答案,想在CView里面调用怎么办?
cattycat 2010-04-05
  • 打赏
  • 举报
回复
就不要加你声明的那些函数了。
cattycat 2010-04-05
  • 打赏
  • 举报
回复
再加上#pragma comment(lib,"")引号中是你的lib名字
yheysj 2010-04-05
  • 打赏
  • 举报
回复
设置那个路径?我把dll&&lib文件拷贝到当前VC工程的目录下,并将两个文件load 到我的工程中!还有机关么?
fox000002 2010-04-05
  • 打赏
  • 举报
回复
使用的时候,lz 的声明也有问题

extern "C" _declspec(dllimport) void ggg(float v1,float v2,float &r);

void _stdcall C_Callfor(float a,float b,float &c)
{
ggg(a,b,c);
}
fox000002 2010-04-05
  • 打赏
  • 举报
回复
ForTran 不区分大小写

导出的函数名按大写给出

yheysj 2010-04-05
  • 打赏
  • 举报
回复
没用的,一个鸟样!!
ForestDB 2010-04-05
  • 打赏
  • 举报
回复
设置路径什么的都对了么?
还有那些调用惯例的处理是正确的么?
MSVC vs. MinGW 之 (lib,dll,def,obj,exe) vs (a,dll,def,o,exe) 玩转攻略手记 一份粗糙的研究记录,有待补完和整理。 MinGW: c -> o gcc -c a.c c -> exe gcc a.c libs.o -o a.exe (从主程序a.c,附加libs,生成a.exe) o -> exe gcc a.o b.o ... -o main.exe c -> dll,def,a gcc a.c -shared -o a.dll -Wl,--output-def,a.def,--out-implib,liba.a a -> dll a2dll liba.a dll -> a: dlltool --dllname a.dll --def a.def --output-lib liba.a (需要def文件) a -> def: dumpbin /exports lib.a > lib.def (在windows上调用,def需要修改) dll -> def : pexports a.dll -o > a.def (这里的-o是指给函数标序号) lib -> def : reimp -d a.lib lib -> a: (for __cdecl functions in most case) reimp a.lib; (for __stdcall functions) MSVC: c -> lib cl /LD a.c (注意已经定义了export列表) c -> dll cl /LD a.c c -> obj cl /c a.c c -> exe cl a.c /out:a.exe dll ->lib lib /machine:ix86 /def:a.def /out:a.lib (需要def文件) obj ->lib lib a.obj b.obj... /out:mylib.lib dll ->def DUMPBIN a.dll /EXPORTS /OUT:a.def (生成的def需要做修正) lib ->def reimp -d a.lib (这个要在MSYS+MinGW下用) 关于这些工具的适用范围可以很容易的理解和记忆。 dll和exe都是PE文件,所以可以使用pexports. lib和a是静态库文件,都是归档类型,不是PE格式。所以不能使用pexports. dll可以使用dlltool. lib可以使用lib, 和reimp(lib->a工具) 所有的bin文件,包括dll,exe,lib,a都可以使用dumpbin. 参考: http://hi.baidu.com/kaien_space/blog/item/5e77fafa2ba9ff16a8d3110a.html Mingw官网文档: http://www.mingw.org/wiki/MSVC_and_MinGW_DLLs http://oldwiki.mingw.org/index.php/CreateImportLibraries http://www.mingw.org/wiki/FAQ http://hi.baidu.com/opaquefog/blog/item/9b21b6deb324e25dccbf1ab7.html http://qzone.qq.com/blog/8330936-1238659272 http://hi.baidu.com/jzinfo/blog/item/b0aa1d308de99f9da8018e00.html 本篇测试用代码: 1. main.cpp #include #include #include "mylib.h" using namespace std; int main() { char str[]="Hello world!"; printhello(str); return 0; } 2. mylib.cpp #include #include #include "mylib.h" using namespace std; void EXPORT printhello(char *str) { cout << str << endl; } 3. mylib.h #define EXPORT __declspec(

64,682

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧