无法在动态链接库中找到过程入口点axiom_attribute_create

时间:2015-02-23 11:57:44

标签: c linker entry-point stdcall axis2c

我在c中有一个项目,我想用MinGW在CodeBlocks中编译它。 我试图链接其所需的库,但我得到了

  

未定义的引用错误

所以我搜索并发现我使用的库是用MVC ++编译的,不能和MinGW一起使用。 (我不是c的专家,所以我有点困惑。)我找到了This链接并按照他们的说法解决了我的问题。

我从原来的axis2c .dll文件中创建了axis2c .a文件。

  • 我使用reimp
  • 创建了.def文件
  • 然后我修改了.def文件中的每个stdcall函数(我更改了#34; _name @ ordinal"到" name")
  • 然后我使用dlltool创建.a文件。

我将.a文件链接到我的项目。一切都很顺利,我可以编译我的项目。但是当我试图运行它。我收到了这个错误。

  

无法在动态链接库

中找到过程入口点axiom_attribute_create

我已将此项目纳入此Link

我使用MinGW下载了一个CodeBlock。 codeblocks-10.05mingw-setup.exe(我想使用 MinGw32bit )。然后我按照@mikekinghan所说的步骤进行操作设置构建选项。然后我建立了这个项目。我收到了这个错误。 我已经将Axis2c lib文件夹添加到路径环境中。 (我甚至将axiom.dll复制到" C:\ Windows \ SysWOW64"正如@mikekinghan建议的那样。

这是构建日志:

-------------- Build: Debug in Math ---------------

mingw32-gcc.exe -Wall  -g    -IC:\Tools\axis2c\include -IE:\dev\CodeBlocks\MinGW  -c E:\dev\c\Math\adb_addOperatorResponse.c -o obj\Debug\adb_addOperatorResponse.o
In file included from C:\Tools\axis2c\include/platforms/axutil_platform_auto_sense.h:40,
                 from C:\Tools\axis2c\include/axutil_dll_desc.h:31,
                 from C:\Tools\axis2c\include/axutil_class_loader.h:31,
                 from C:\Tools\axis2c\include/axis2_util.h:24,
                 from E:\dev\c\Math\adb_addOperatorResponse.h:21,
                 from E:\dev\c\Math\adb_addOperatorResponse.c:10:
C:\Tools\axis2c\include/platforms/windows/axutil_windows.h:221:5: warning: "/*" within comment
E:\dev\c\Math\adb_addOperatorResponse.c: In function 'adb_addOperatorResponse_serialize_obj':
E:\dev\c\Math\adb_addOperatorResponse.c:466: warning: format '%I32d' expects type 'long int', but argument 3 has type 'int'
E:\dev\c\Math\adb_addOperatorResponse.c:374: warning: unused variable 'ns_already_defined'
E:\dev\c\Math\adb_addOperatorResponse.c:372: warning: unused variable 'qname_prefix'
E:\dev\c\Math\adb_addOperatorResponse.c:371: warning: unused variable 'qname_uri'
E:\dev\c\Math\adb_addOperatorResponse.c:367: warning: unused variable 'tag_closed'
E:\dev\c\Math\adb_addOperatorResponse.c: In function 'adb_addOperatorResponse_reset_addOperatorReturn':
E:\dev\c\Math\adb_addOperatorResponse.c:568: warning: unused variable 'element'
E:\dev\c\Math\adb_addOperatorResponse.c:567: warning: unused variable 'count'
E:\dev\c\Math\adb_addOperatorResponse.c:566: warning: unused variable 'i'
mingw32-gcc.exe -Wall  -g    -IC:\Tools\axis2c\include -IE:\dev\CodeBlocks\MinGW  -c E:\dev\c\Math\axis2_extension_mapper.c -o obj\Debug\axis2_extension_mapper.o
In file included from C:\Tools\axis2c\include/platforms/axutil_platform_auto_sense.h:40,
                 from C:\Tools\axis2c\include/axutil_dll_desc.h:31,
                 from C:\Tools\axis2c\include/axutil_class_loader.h:31,
                 from C:\Tools\axis2c\include/axis2_util.h:24,
                 from E:\dev\c\Math\axis2_extension_mapper.h:14,
                 from E:\dev\c\Math\axis2_extension_mapper.c:10:
C:\Tools\axis2c\include/platforms/windows/axutil_windows.h:221:5: warning: "/*" within comment
E:\dev\c\Math\axis2_extension_mapper.c: In function 'axis2_extension_mapper_type_from_node':
E:\dev\c\Math\axis2_extension_mapper.c:31: warning: unused variable 'element_qname'
mingw32-gcc.exe -Wall  -g    -IC:\Tools\axis2c\include -IE:\dev\CodeBlocks\MinGW  -c E:\dev\c\Math\axis2_stub_MathService.c -o obj\Debug\axis2_stub_MathService.o
In file included from C:\Tools\axis2c\include/platforms/axutil_platform_auto_sense.h:40,
                 from C:\Tools\axis2c\include/axutil_dll_desc.h:31,
                 from C:\Tools\axis2c\include/axutil_class_loader.h:31,
                 from C:\Tools\axis2c\include/axis2_util.h:24,
                 from C:\Tools\axis2c\include/neethi_includes.h:22,
                 from C:\Tools\axis2c\include/neethi_operator.h:29,
                 from C:\Tools\axis2c\include/neethi_policy.h:29,
                 from C:\Tools\axis2c\include/axis2_svc_client.h:56,
                 from C:\Tools\axis2c\include/axis2_stub.h:35,
                 from C:\Tools\axis2c\include/axis2_client.h:31,
                 from E:\dev\c\Math\axis2_stub_MathService.h:14,
                 from E:\dev\c\Math\axis2_stub_MathService.c:10:
C:\Tools\axis2c\include/platforms/windows/axutil_windows.h:221:5: warning: "/*" within comment
E:\dev\c\Math\axis2_stub_MathService.c: In function 'axis2_stub_populate_services_for_MathService':
E:\dev\c\Math\axis2_stub_MathService.c:72: warning: unused variable 'status'
E:\dev\c\Math\axis2_stub_MathService.c:71: warning: unused variable 'neethi_policy'
E:\dev\c\Math\axis2_stub_MathService.c:70: warning: unused variable 'policy_root_ele'
E:\dev\c\Math\axis2_stub_MathService.c:69: warning: unused variable 'policy_node'
E:\dev\c\Math\axis2_stub_MathService.c:68: warning: unused variable 'desc'
E:\dev\c\Math\axis2_stub_MathService.c:66: warning: unused variable 'policy_include'
E:\dev\c\Math\axis2_stub_MathService.c: In function 'axis2_stub_on_complete_MathService_addOperator':
E:\dev\c\Math\axis2_stub_MathService.c:277: warning: unused variable 'soap_fault'
mingw32-gcc.exe -Wall  -g    -IC:\Tools\axis2c\include -IE:\dev\CodeBlocks\MinGW  -c E:\dev\c\Math\main.c -o obj\Debug\main.o
In file included from C:\Tools\axis2c\include/platforms/axutil_platform_auto_sense.h:40,
                 from C:\Tools\axis2c\include/axutil_dll_desc.h:31,
                 from C:\Tools\axis2c\include/axutil_class_loader.h:31,
                 from C:\Tools\axis2c\include/axis2_util.h:24,
                 from C:\Tools\axis2c\include/neethi_includes.h:22,
                 from C:\Tools\axis2c\include/neethi_operator.h:29,
                 from C:\Tools\axis2c\include/neethi_policy.h:29,
                 from C:\Tools\axis2c\include/axis2_svc_client.h:56,
                 from C:\Tools\axis2c\include/axis2_stub.h:35,
                 from C:\Tools\axis2c\include/axis2_client.h:31,
                 from E:\dev\c\Math\axis2_stub_MathService.h:14,
                 from E:\dev\c\Math\main.c:1:
C:\Tools\axis2c\include/platforms/windows/axutil_windows.h:221:5: warning: "/*" within comment
E:\dev\c\Math\main.c:3: warning: second argument of 'main' should be 'char **'
E:\dev\c\Math\main.c: In function 'main':
E:\dev\c\Math\main.c:8: warning: unused variable 'operation'
mingw32-gcc.exe -Wall  -g    -IC:\Tools\axis2c\include -IE:\dev\CodeBlocks\MinGW  -c E:\dev\c\Math\adb_addOperator.c -o obj\Debug\adb_addOperator.o
In file included from C:\Tools\axis2c\include/platforms/axutil_platform_auto_sense.h:40,
                 from C:\Tools\axis2c\include/axutil_dll_desc.h:31,
                 from C:\Tools\axis2c\include/axutil_class_loader.h:31,
                 from C:\Tools\axis2c\include/axis2_util.h:24,
                 from E:\dev\c\Math\adb_addOperator.h:21,
                 from E:\dev\c\Math\adb_addOperator.c:10:
C:\Tools\axis2c\include/platforms/windows/axutil_windows.h:221:5: warning: "/*" within comment
E:\dev\c\Math\adb_addOperator.c: In function 'adb_addOperator_serialize_obj':
E:\dev\c\Math\adb_addOperator.c:574: warning: format '%I32d' expects type 'long int', but argument 3 has type 'int'
E:\dev\c\Math\adb_addOperator.c:640: warning: format '%I32d' expects type 'long int', but argument 3 has type 'int'
E:\dev\c\Math\adb_addOperator.c:480: warning: unused variable 'ns_already_defined'
E:\dev\c\Math\adb_addOperator.c:478: warning: unused variable 'qname_prefix'
E:\dev\c\Math\adb_addOperator.c:477: warning: unused variable 'qname_uri'
E:\dev\c\Math\adb_addOperator.c:473: warning: unused variable 'tag_closed'
E:\dev\c\Math\adb_addOperator.c: In function 'adb_addOperator_reset_num1':
E:\dev\c\Math\adb_addOperator.c:742: warning: unused variable 'element'
E:\dev\c\Math\adb_addOperator.c:741: warning: unused variable 'count'
E:\dev\c\Math\adb_addOperator.c:740: warning: unused variable 'i'
E:\dev\c\Math\adb_addOperator.c: In function 'adb_addOperator_reset_num2':
E:\dev\c\Math\adb_addOperator.c:848: warning: unused variable 'element'
E:\dev\c\Math\adb_addOperator.c:847: warning: unused variable 'count'
E:\dev\c\Math\adb_addOperator.c:846: warning: unused variable 'i'
mingw32-g++.exe -LC:\Tools\axis2c\include -LE:\dev\CodeBlocks\MinGW\lib  -o bin\Debug\Math.exe obj\Debug\adb_addOperatorResponse.o obj\Debug\axis2_extension_mapper.o obj\Debug\axis2_stub_MathService.o obj\Debug\main.o obj\Debug\adb_addOperator.o   -laxiom -laxutil -laxis2_engine -laxis2_parser  
e:/dev/codeblocks/mingw/bin/../lib/gcc/mingw32/4.4.1/../../../../mingw32/bin/ld.exe: cannot find -laxiom
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 6 seconds)
1 errors, 35 warnings

似乎我错误地把../include放在搜索目录>链接器中我修正了这个错误。

enter image description here enter image description here enter image description here

我构建项目然后我得到了这个:

-------------- Build: Debug in Math ---------------

mingw32-gcc.exe -Wall  -g    -IC:\Tools\axis2c\include -IE:\dev\CodeBlocks\MinGW  -c E:\dev\c\Math\adb_addOperatorResponse.c -o obj\Debug\adb_addOperatorResponse.o
In file included from C:\Tools\axis2c\include/platforms/axutil_platform_auto_sense.h:40,
                 from C:\Tools\axis2c\include/axutil_dll_desc.h:31,
                 from C:\Tools\axis2c\include/axutil_class_loader.h:31,
                 from C:\Tools\axis2c\include/axis2_util.h:24,
                 from E:\dev\c\Math\adb_addOperatorResponse.h:21,
                 from E:\dev\c\Math\adb_addOperatorResponse.c:10:
C:\Tools\axis2c\include/platforms/windows/axutil_windows.h:221:5: warning: "/*" within comment
E:\dev\c\Math\adb_addOperatorResponse.c: In function 'adb_addOperatorResponse_serialize_obj':
E:\dev\c\Math\adb_addOperatorResponse.c:466: warning: format '%I32d' expects type 'long int', but argument 3 has type 'int'
mingw32-gcc.exe -Wall  -g    -IC:\Tools\axis2c\include -IE:\dev\CodeBlocks\MinGW  -c E:\dev\c\Math\axis2_extension_mapper.c -o obj\Debug\axis2_extension_mapper.o
In file included from C:\Tools\axis2c\include/platforms/axutil_platform_auto_sense.h:40,
                 from C:\Tools\axis2c\include/axutil_dll_desc.h:31,
                 from C:\Tools\axis2c\include/axutil_class_loader.h:31,
                 from C:\Tools\axis2c\include/axis2_util.h:24,
                 from E:\dev\c\Math\axis2_extension_mapper.h:14,
                 from E:\dev\c\Math\axis2_extension_mapper.c:10:
C:\Tools\axis2c\include/platforms/windows/axutil_windows.h:221:5: warning: "/*" within comment
mingw32-gcc.exe -Wall  -g    -IC:\Tools\axis2c\include -IE:\dev\CodeBlocks\MinGW  -c E:\dev\c\Math\axis2_stub_MathService.c -o obj\Debug\axis2_stub_MathService.o
In file included from C:\Tools\axis2c\include/platforms/axutil_platform_auto_sense.h:40,
                 from C:\Tools\axis2c\include/axutil_dll_desc.h:31,
                 from C:\Tools\axis2c\include/axutil_class_loader.h:31,
                 from C:\Tools\axis2c\include/axis2_util.h:24,
                 from C:\Tools\axis2c\include/neethi_includes.h:22,
                 from C:\Tools\axis2c\include/neethi_operator.h:29,
                 from C:\Tools\axis2c\include/neethi_policy.h:29,
                 from C:\Tools\axis2c\include/axis2_svc_client.h:56,
                 from C:\Tools\axis2c\include/axis2_stub.h:35,
                 from C:\Tools\axis2c\include/axis2_client.h:31,
                 from E:\dev\c\Math\axis2_stub_MathService.h:14,
                 from E:\dev\c\Math\axis2_stub_MathService.c:10:
C:\Tools\axis2c\include/platforms/windows/axutil_windows.h:221:5: warning: "/*" within comment
mingw32-gcc.exe -Wall  -g    -IC:\Tools\axis2c\include -IE:\dev\CodeBlocks\MinGW  -c E:\dev\c\Math\main.c -o obj\Debug\main.o
In file included from C:\Tools\axis2c\include/platforms/axutil_platform_auto_sense.h:40,
                 from C:\Tools\axis2c\include/axutil_dll_desc.h:31,
                 from C:\Tools\axis2c\include/axutil_class_loader.h:31,
                 from C:\Tools\axis2c\include/axis2_util.h:24,
                 from C:\Tools\axis2c\include/neethi_includes.h:22,
                 from C:\Tools\axis2c\include/neethi_operator.h:29,
                 from C:\Tools\axis2c\include/neethi_policy.h:29,
                 from C:\Tools\axis2c\include/axis2_svc_client.h:56,
                 from C:\Tools\axis2c\include/axis2_stub.h:35,
                 from C:\Tools\axis2c\include/axis2_client.h:31,
                 from E:\dev\c\Math\axis2_stub_MathService.h:14,
                 from E:\dev\c\Math\main.c:1:
C:\Tools\axis2c\include/platforms/windows/axutil_windows.h:221:5: warning: "/*" within comment
E:\dev\c\Math\main.c:3: warning: second argument of 'main' should be 'char **'
mingw32-gcc.exe -Wall  -g    -IC:\Tools\axis2c\include -IE:\dev\CodeBlocks\MinGW  -c E:\dev\c\Math\adb_addOperator.c -o obj\Debug\adb_addOperator.o
In file included from C:\Tools\axis2c\include/platforms/axutil_platform_auto_sense.h:40,
                 from C:\Tools\axis2c\include/axutil_dll_desc.h:31,
                 from C:\Tools\axis2c\include/axutil_class_loader.h:31,
                 from C:\Tools\axis2c\include/axis2_util.h:24,
                 from E:\dev\c\Math\adb_addOperator.h:21,
                 from E:\dev\c\Math\adb_addOperator.c:10:
C:\Tools\axis2c\include/platforms/windows/axutil_windows.h:221:5: warning: "/*" within comment
E:\dev\c\Math\adb_addOperator.c: In function 'adb_addOperator_serialize_obj':
E:\dev\c\Math\adb_addOperator.c:574: warning: format '%I32d' expects type 'long int', but argument 3 has type 'int'
E:\dev\c\Math\adb_addOperator.c:640: warning: format '%I32d' expects type 'long int', but argument 3 has type 'int'
mingw32-g++.exe -LC:\Tools\axis2c\lib -LE:\dev\CodeBlocks\MinGW\lib  -o bin\Debug\Math.exe obj\Debug\adb_addOperatorResponse.o obj\Debug\axis2_extension_mapper.o obj\Debug\axis2_stub_MathService.o obj\Debug\main.o obj\Debug\adb_addOperator.o   -laxiom -laxutil -laxis2_engine -laxis2_parser  
obj\Debug\adb_addOperatorResponse.o: In function `adb_addOperatorResponse_create':
E:/dev/c/Math/adb_addOperatorResponse.c:58: undefined reference to `_imp__axutil_error_set_error_number'
E:/dev/c/Math/adb_addOperatorResponse.c:58: undefined reference to `_imp__axutil_error_set_status_code'
E:/dev/c/Math/adb_addOperatorResponse.c:64: undefined reference to `_imp__axutil_strdup'
E:/dev/c/Math/adb_addOperatorResponse.c:67: undefined reference to `_imp__axutil_qname_create'
obj\Debug\adb_addOperatorResponse.o: In function `adb_addOperatorResponse_free_obj':
E:/dev/c/Math/adb_addOperatorResponse.c:139: undefined reference to `_imp__axutil_error_set_error_number'
E:/dev/c/Math/adb_addOperatorResponse.c:139: undefined reference to `_imp__axutil_error_set_status_code'
E:/dev/c/Math/adb_addOperatorResponse.c:139: undefined reference to `_imp__axutil_error_set_status_code'
E:/dev/c/Math/adb_addOperatorResponse.c:150: undefined reference to `_imp__axutil_qname_free'
obj\Debug\adb_addOperatorResponse.o: In function `adb_addOperatorResponse_deserialize_obj':
E:/dev/c/Math/adb_addOperatorResponse.c:209: undefined reference to `_imp__axutil_error_set_error_number'
E:/dev/c/Math/adb_addOperatorResponse.c:209: undefined reference to `_imp__axutil_error_set_status_code'
E:/dev/c/Math/adb_addOperatorResponse.c:209: undefined reference to `_imp__axutil_error_set_status_code'
E:/dev/c/Math/adb_addOperatorResponse.c:215: undefined reference to `_imp__axiom_node_get_next_sibling'
E:/dev/c/Math/adb_addOperatorResponse.c:213: undefined reference to `_imp__axiom_node_get_node_type'
E:/dev/c/Math/adb_addOperatorResponse.c:227: undefined reference to `_imp__axiom_node_get_data_element'
E:/dev/c/Math/adb_addOperatorResponse.c:228: undefined reference to `_imp__axiom_element_get_qname'
E:/dev/c/Math/adb_addOperatorResponse.c:229: undefined reference to `_imp__axutil_qname_equals'
E:/dev/c/Math/adb_addOperatorResponse.c:232: undefined reference to `_imp__axiom_node_get_first_child'
E:/dev/c/Math/adb_addOperatorResponse.c:237: undefined reference to `_imp__axutil_qname_to_string'
E:/dev/c/Math/adb_addOperatorResponse.c:237: undefined reference to `_imp__axutil_qname_to_string'
E:/dev/c/Math/adb_addOperatorResponse.c:260: undefined reference to `_imp__axiom_node_get_next_sibling'
E:/dev/c/Math/adb_addOperatorResponse.c:258: undefined reference to `_imp__axiom_node_get_node_type'
E:/dev/c/Math/adb_addOperatorResponse.c:264: undefined reference to `_imp__axiom_node_get_data_element'
E:/dev/c/Math/adb_addOperatorResponse.c:265: undefined reference to `_imp__axiom_element_get_qname'
E:/dev/c/Math/adb_addOperatorResponse.c:268: undefined reference to `_imp__axutil_qname_create'
E:/dev/c/Math/adb_addOperatorResponse.c:272: undefined reference to `_imp__axutil_qname_equals'
E:/dev/c/Math/adb_addOperatorResponse.c:274: undefined reference to `_imp__axutil_qname_equals'
E:/dev/c/Math/adb_addOperatorResponse.c:280: undefined reference to `_imp__axiom_element_get_text'
E:/dev/c/Math/adb_addOperatorResponse.c:298: undefined reference to `_imp__axutil_qname_free'
E:/dev/c/Math/adb_addOperatorResponse.c:308: undefined reference to `_imp__axutil_qname_free'
E:/dev/c/Math/adb_addOperatorResponse.c:317: undefined reference to `_imp__axutil_qname_free'
obj\Debug\adb_addOperatorResponse.o: In function `adb_addOperatorResponse_serialize_obj':
E:/dev/c/Math/adb_addOperatorResponse.c:392: undefined reference to `_imp__axutil_error_set_error_number'
E:/dev/c/Math/adb_addOperatorResponse.c:392: undefined reference to `_imp__axutil_error_set_status_code'
E:/dev/c/Math/adb_addOperatorResponse.c:392: undefined reference to `_imp__axutil_error_set_status_code'
E:/dev/c/Math/adb_addOperatorResponse.c:395: undefined reference to `_imp__axutil_hash_make'
E:/dev/c/Math/adb_addOperatorResponse.c:398: undefined reference to `_imp__axiom_namespace_create'
E:/dev/c/Math/adb_addOperatorResponse.c:401: undefined reference to `_imp__axutil_strdup'
E:/dev/c/Math/adb_addOperatorResponse.c:401: undefined reference to `_imp__axutil_hash_set'
E:/dev/c/Math/adb_addOperatorResponse.c:404: undefined reference to `_imp__axiom_element_create'
E:/dev/c/Math/adb_addOperatorResponse.c:407: undefined reference to `_imp__axiom_element_set_namespace'
E:/dev/c/Math/adb_addOperatorResponse.c:411: undefined reference to `_imp__axiom_data_source_create'
E:/dev/c/Math/adb_addOperatorResponse.c:412: undefined reference to `_imp__axiom_data_source_get_stream'
E:/dev/c/Math/adb_addOperatorResponse.c:414: undefined reference to `_imp__axutil_hash_get'
E:/dev/c/Math/adb_addOperatorResponse.c:418: undefined reference to `_imp__axutil_hash_set'
E:/dev/c/Math/adb_addOperatorResponse.c:420: undefined reference to `_imp__axiom_namespace_create'
E:/dev/c/Math/adb_addOperatorResponse.c:420: undefined reference to `_imp__axiom_element_declare_namespace_assume_param_ownership'
E:/dev/c/Math/adb_addOperatorResponse.c:436: undefined reference to `_imp__axutil_strlen'
E:/dev/c/Math/adb_addOperatorResponse.c:436: undefined reference to `_imp__axutil_strlen'
E:/dev/c/Math/adb_addOperatorResponse.c:441: undefined reference to `_imp__axutil_strlen'
E:/dev/c/Math/adb_addOperatorResponse.c:441: undefined reference to `_imp__axutil_strlen'
E:/dev/c/Math/adb_addOperatorResponse.c:458: undefined reference to `_imp__axutil_strcmp'
Process terminated with status 1 (0 minutes, 9 seconds)
50 errors, 9 warnings

形成@MikeKinghan试图教给我的东西,我现在理解了Linker命令的含义,我看到这次Linker设置正确。但为什么不能正确编译?

2 个答案:

答案 0 :(得分:0)

我不遵循你采取的步骤背后的原因而不是 有关于你所做的事情的任何具体数据,所以这是第一原则的回答"。

如果您想使用 Microsoft的链接器(您 > )将DLL foo.dll与您的程序相关联,那么您不能 将foo.dll直接传递给链接器。如您所知,您必须传递导入foo.lib,即 一个小的静态库"存根"表示foo.dll导出的函数。在运行时, 程序加载器扫描这些存根,并且(如果可能的话)用匹配的引用替换它们 通过根据the Windows DLL Search Path

搜索可用的DLL来找到它找到的导出函数

如果您想使用MinGW GNU链接器(您 做)将foo.dll与您的程序链接, 导入库foo.lib是必要的。该链接器可以直接链接foo.dll。你没理由 不这样做。

使用MinGW GNU链接器直接将foo.dll链接到您的程序,链接器,当然, 必须能够通过其遵循的规则在链接时找到foo.dll以查找库,无论是静态还是 动态。就像微软的链接器一样,DLL的成功链接并不能保证DLL 也将在程序加载器的 runtime 中找到。程序加载器根据搜索DLL Windows DLL搜索路径:它不知道或关心您用于链接程序的链接器。您 必须确保链接器在链接时找到DLL,然后你需要确保该程序 loader会在运行时找到它。

您如何告诉MinGW链接器直接链接foo.dll?您只需遵循传递库的规则即可 链接器,为documented here

但在你可以尝试之前还有一个必须满足的基本条件。 您 无法将32位DLL与64位程序链接,反之亦然。你说你正在用64位MinGW构建; 因此,默认情况下,它将构建64位可执行文件,如果您正在构建64位.exe,则必须将其与axis2c DLL的64位版本链接。

我不知道你的axis2c库的位置,但是如果你下载了Apache的v1.6.0二进制存档 那么你有32位的DLL。

您可以告诉您的64位MinGW构建一个32位.exe,但您可能更愿意将其与64位axis2c DLL链接。幸好, Google提供64位版本。从here下载。 64位存档是 x86_64-wsdk7.1-r7acae470da50.7z。 在方便的地方下载;用7-Zip提取它,然后我建议你将提取的文件夹重命名为识别它的东西 显然,就像axis2c-x86_64-google

现在,我将在命令提示符下编译并链接一个示例axis2c程序,遵循链接器查找库的规则。 我构建的程序是Apache包中提供的示例程序之一:axis2c-bin-1.6.0-win32\samples\src\client\echo。 我随机选择它:它只包含一个源文件,即echo.c。我的工具链是64位GCC 4.9.2。我下载了64位axis2c包,解压缩并重命名为 C:\develop\stackoverflow\axis2c-x86_64-google

我在echo目录中打开命令提示符并输入:

gcc -IC:\develop\stackoverflow\axis2c-x86_64-google\include\axis2-1.6.0 -c echo.c -o echo.o

我告诉gccecho.c编译为echo.o,并且应该搜索非标准的头文件 在C:\develop\stackoverflow\axis2c-x86_64-google\include\axis2-1.6.0。 (基本了解如何编译和 将程序与GCC联系起来,我建议您阅读this tutorial)。

我收到编译器警告:

  

警告请在windows.h之前包含winsock2.h

但它不是错误所以我不会为了演示目的而担心它。

接下来,我想将刚刚构建的echo.o我需要的axis2c DLL链接到 制作一个名为axis2c-echo.exe的程序。所以我输入:

gcc -o axis2c-echo.exe echo.o  -LC:\develop\stackoverflow\axis2c-x86_64-google\lib  -laxiom -laxutil -laxis2_engine -laxis2_parser

我告诉gcc除了目标文件echo.o之外,程序还需要链接库(-laxiomaxutilaxis2_engineaxis2_parser, 并且链接器应该在C:\develop\stackoverflow\axis2c-x86_64-google\lib中查找非标准库。

请注意,我不需要告诉链接器,例如axiom库是axiom.dll而不是axiom.liblibaxiom.a-laxiom告诉你 链接器在给定的搜索目录中查找这些的任何,如果碰巧找到动态库(axiom.dll),它会更喜欢任何静态库 图书馆axiom.liblibaxiom.a。在C:\develop\stackoverflow\axis2c-x86_64-google\lib中,它实际上会找到axiom.dllaxiom.lib, 并且更喜欢前者;但你不需要关心。

联动命令成功,所以现在我在同一目录中有一个程序axis2c-echo.exe。我会运行它:

axis2c-echo

但我不能。我刚刚得到一个Windows错误对话框,上面写着:

  

此程序无法启动,因为您的计算机缺少axiom.dll。尝试重新安装程序以修复此错误。

问题是axiom.dll是从C:\develop\stackoverflow\axis2c-x86_64-google\lib链接的,axis2c不是其中之一 程序加载程序在运行时搜索DLL的位置。

现在如果我计划在我的计算机上定期运行axis2c程序,我会通过安装64位C:\Windows\SysWOW64 DLL来解决这个问题 在C:\develop\stackoverflow\axis2c-x86_64-google\lib中,因为64位Windows总是在那里搜索DLL。但我不打算这样做,所以我只是 暂时将set PATH=%PATH%;C:\develop\stackoverflow\axis2c-x86_64-google\lib 添加到Windows DLL搜索路径。 Windows DLL搜索路径上的最后一站 是: PATH环境变量中列出的目录。因此,在我的命令提示符下,我将输入:

axis2c-echo

然后再次运行echo。这次,输出是:

  

未设置AXIS2C_HOME - 写入日志。 DIR   使用端点:http://localhost:9090/axis2/services/echo   创建服务客户端时出错,请再次检查AXIS2C_HOME

现在程序本身正在抱怨,但这对我来说已经足够了!它已编译,链接,加载, 产生了一些输出并且优雅地完成了。

现在可能很明显如何设置Code :: Blocks项目来构建同一个程序:

  • main.c目录中创建一个C语言控制台项目。
  • 从项目中删除默认的echo.c源文件
  • 将单个源文件C:\develop\stackoverflow\axis2c-x86_64-google\include\axis2-1.6.0添加到项目中。
  • 在项目的构建选项中 - > 搜索目录 - > 编译器,添加path\to\your\axis2c-1.6.0\header-files (或C:\develop\stackoverflow\axis2c-x86_64-google\lib
  • 在项目的构建选项中 - > 搜索目录 - > 链接器,添加path\to\your\axis2c-1.6.0\libraries (或-laxiom -laxutil -laxis2_engine -laxis2_parser
  • 在项目的构建选项中 - > 链接器设置 - > 其他链接器选项,添加echo

这不是您在C :: B中成功配置此项目的唯一方法,但它对应于某人通常构建该项目的方式 命令提示符下的project,意味着C :: B执行的工具链命令将是简洁和正常的。

如果按照以下步骤构建示例{{1}}项目,那么成功配置自己的项目就不会有太大困难。

答案 1 :(得分:0)

您的项目包含5个源文件,每个文件都必须成功编译,然后全部编译 需要链接在一起,以及一些axis2c DLL,以构建您的程序。

让我们看看您的构建日志。

5个源文件中的每一个都有一个编译命令:

mingw32-gcc.exe -Wall  -g    -IC:\Tools\axis2c\include -IE:\dev\CodeBlocks\MinGW  -c E:\dev\c\Math\adb_addOperatorResponse.c -o obj\Debug\adb_addOperatorResponse.o
...
mingw32-gcc.exe -Wall  -g    -IC:\Tools\axis2c\include -IE:\dev\CodeBlocks\MinGW  -c E:\dev\c\Math\axis2_extension_mapper.c -o obj\Debug\axis2_extension_mapper.o
...
mingw32-gcc.exe -Wall  -g    -IC:\Tools\axis2c\include -IE:\dev\CodeBlocks\MinGW  -c E:\dev\c\Math\axis2_stub_MathService.c -o obj\Debug\axis2_stub_MathService.o
...
mingw32-gcc.exe -Wall  -g    -IC:\Tools\axis2c\include -IE:\dev\CodeBlocks\MinGW  -c E:\dev\c\Math\main.c -o obj\Debug\main.o
...
mingw32-gcc.exe -Wall  -g    -IC:\Tools\axis2c\include -IE:\dev\CodeBlocks\MinGW  -c E:\dev\c\Math\adb_addOperator.c -o obj\Debug\adb_addOperator.o
...

然后有一个链接命令:

mingw32-g++.exe -LC:\Tools\axis2c\include -LE:\dev\CodeBlocks\MinGW\lib  -o bin\Debug\Math.exe obj\Debug\adb_addOperatorResponse.o obj\Debug\axis2_extension_mapper.o obj\Debug\axis2_stub_MathService.o obj\Debug\main.o obj\Debug\adb_addOperator.o   -laxiom -laxutil -laxis2_engine -laxis2_parser
...

将这些命令复制/粘贴到您可以从头到尾看到它们的地方。

在我放置的所有地方......',编译器或链接器都对您的程序提出了一些抱怨。

5个编译命令发出的所有诊断都是警告。无论什么是不对的,它实际上并没有阻止编译器编译源代码 将文件(.c)放入目标文件(.o)中。如果任何.c文件中存在任何编译错误,则编译器将无法创建.o文件, 并且构建将在不尝试链接程序的情况下停止,因为在缺少某些目标文件时将其链接起来将是徒劳的。

意味着您不必担心编译器警告。他们可能会警告您的程序中可能存在错误 ,其中一些是。 所以你需要修理它们。

链接命令失败。你没有程序,这是你的首要问题。

为了理解编译器和链接器诊断,并且能够自己修复它们,您需要了解编译器和链接器命令的含义。

我们可以看到工具链Code :: Blocks正在为您推动MinGW项目的32位Windows端口GCC (The GNU Compiler Collection)。 GCC是C / C ++编程工具链的父亲:它支持每个操作系统和每个处理器;它在每个应用领域中使用。 它完全独立于你可以驱动它的众多IDE,以及所有这些IDE(Eclipse,Code :: Blocks,KDevelop,CodeLite,Anjuta, Dev-C ++等)以隐含的假设来了解您是否了解编译和链接GCC。至少,他们都不能拯救你 了解与GCC的编译和链接。

在继续之前,所有这一切的生命教训将是:将你的IDE拉开一段时间。了解如何使用GCC构建程序。 然后很明显如何使用IDE。

所有编译命令都由mingw32-gcc.exe执行。那是GCC工具驱动程序,它的 C编译器"姿势"。如果你查看它安装的目录, 也许C:\MinGW\bin,您还会看到程序gcc.exeg++.exe以及带有前缀mingw32-的两个程序。所有这些计划 是GCC工具驱动程序,在不同的"姿势"适应不同的角色。

您的链接命令由mingw32-g++.exe执行。这是GCC工具驱动程序,它的 C ++链接器"姿势"。 Code :: Blocks似乎令人费解 默认情况下,将 C ++ 链接器配置为链接 C 程序。这样做是因为C ++链接适用于所有C,所有C ++或两者的混合的程序。 但C链接不适用于C ++程序。

无论什么"姿势"通过名称建议,GCC工具驱动程序通过检查其命令行和文件扩展名上的选项来确定需要做什么 传递给它的文件。因此,它尝试将每个.c源文件编译为C ,因为它们是.c个文件。 如果它们是.cpp个文件,那么它会尝试将它们编译为C ++。一旦确定它做了什么,它就会将工作委托给适当的专业工具 - C编译器,C ++编译器,汇编器,链接器。

这是每个编译命令的含义:

  • -Wall =>启用所有警告
  • -g =>在目标文件中生成调试信息。
  • -IC:\Tools\axis2c\include =>在C:\Tools\axis2c\include
  • 中搜索非标准头文件
  • -IE:\dev\CodeBlocks\MinGW =>还要在E:\dev\CodeBlocks\MinGW
  • 中搜索非标准头文件
  • -c =>刚编译;没有链接
  • E:\dev\c\Math\some_filename.c =>编译此文件。
  • -o obj\Debug\some_filename.o =>输出目标文件obj\Debug\some_filename.o

以下是您的链接命令的含义:

  • -LC:\Tools\axis2c\include =>在.lib
  • 中搜索非标准库(.a.dllC:\Tools\axis2c\include
  • -LE:\dev\CodeBlocks\MinGW\lib =>还可以在E:\dev\CodeBlocks\MinGW\lib
  • 中搜索非标准库
  • -o bin\Debug\Math.exe =>输出可执行文件bin\Debug\Math.exe
  • obj\Debug\adb_addOperatorResponse.o =>链接此目标文件
  • obj\Debug\axis2_extension_mapper.o =>还链接此目标文件
  • obj\Debug\axis2_stub_MathService.o =>还链接此目标文件
  • obj\Debug\main.o =>还链接此目标文件
  • obj\Debug\adb_addOperator.o =>还链接此目标文件
  • -laxiom =>链接库axiom.dll或失败,axiom.liblibaxiom.a,无论它在指定的链接器中最初找到它 搜索目录(-L),或在链接器的标准目录中失败。
  • -laxutil =>链接图书馆axutil.dll或其失败,axutil.liblibaxutil.a等...
  • -laxis2_engine =>链接图书馆axis2_engine.dll或其失败,axis2_engine.liblibaxis2_engine.a等...
  • -laxis2_parser =>链接图书馆axis2_parser.dll或其失败,axis2_parser.liblibaaxis2_parser.a等...

您可能想知道工具驱动程序如何知道链接命令链接命令,而不是C ++编译命令? 它知道没有编译要做,因为没有输入文件可以编译。它们都是目标文件(.o)。 它知道它应该链接它们因为它没有被告知链接它们:-c选项不存在。

您的关联失败,原因是:

e:/dev/codeblocks/mingw/bin/../lib/gcc/mingw32/4.4.1/../../../../mingw32/bin/ld.exe: cannot find -laxiom

ld.exe是链接器本身:GCC工具驱动程序在完成链接时调用的专用工具。 它无法在您指定的任何链接器搜索目录(axiom)中找到您的-L库,当然也不能在 任何标准搜索目录。

现在您已了解链接命令的含义,您可以轻松查看错误。链接器 您指定的搜索目录是:

C:\Tools\axis2c\include
E:\dev\CodeBlocks\MinGW\lib

您的axis2c图书馆(axiom.dll等)不在其中任何一个地方。 C:\Tools\axis2c\include 是您告诉编译器搜索axis2c 头文件的地方:您有:

-IC:\Tools\axis2c\include

因此,如果axis2c头文件所在的位置,那么我想这些库位于C:\Tools\axis2c\lib。看一看。 假设是正确的,那么在C :: B IDE中,您需要从搜索目录 - &gt;中删除错误的C:\Tools\axis2c\include。 <强>链接器 对于您的项目,并将其替换为搜索目录中的正确C:\Tools\axis2c\lib离开C:\Tools\axis2c\include - &gt; <强>编译器下, 因为那是对的。

继续OP的进一步问题

我相信您的axis2c库和标头文件来自Apache's Axis2/C download page 来自档案axis2c-bin-1.6.0-win32.zip

此版本遇到导致链接错误的bug in its header files 你看到的是MinGW32工具链。

此错误不会影响我推荐给您的Google's release of Axis2/C 在我对这个问题的第一个答案中。那时你说你正在使用64位MinGW构建,但它已经存在 很清楚你正在使用32位MinGW构建。在这种情况下,您应该下载Google's 32-bit build Axis2/C

使用7-Zip解压缩存档,并将解压缩的文件夹从axis2c重命名为axis2c-x86-google,以清楚说明它是什么,然后将其复制到方便的位置 为了你的发展。我们假设你把它放在C:\Tools\axis2c-x86-google

然后在C :: B IDE中的搜索目录 - &gt; 编译器,更改:

C:\Tools\axis2c\include

为:

C:\Tools\axis2c-x86-google\include\axis2-1.6.0

并在搜索目录 - &gt; 链接器,更改:

C:\Tools\axis2c\lib

为:

C:\Tools\axis2c-x86-google\lib

Apache发行版中名为axiom.dll的库在Google的发行版中称为axis2_axiom.dll。因此 在链接器设置 - &gt;中其他链接器选项,更改:

-laxiom

为:

-laxis2_axiom

然后您的程序成功链接(对我而言)。

再次继续

根据您的评论,程序现在无法在运行时加载错误:

The procedure entry point axis2_callback_create could not be located in the dynamic link library

这意味着在运行时找不到提供axis2_callback_create的正确DLL。

你说:

  

我还添加了&#34; lib&#34;到路径环境。并且还将lib dll文件添加到&#34; C:\ Windows \ SysWOW64&#34;

  • 做其中一个,而不是两个。
  • 根据您将Axis2 / C库目录添加到PATH所做的操作,它可能没有任何效果。
    • 如果您在shell(命令提示符)窗口中执行此操作,该窗口与您尝试运行的窗口不同 程序,然后它将没有任何效果,因为您在shell中进行的环境设置仅适用于 在同一个shell中启动的进程。
    • 如果您是通过修改高级系统设置中的PATH环境变量来实现此目的的那么 对您尝试运行程序的shell已经打开没有任何影响。您需要保存高级系统设置 然后再次尝试在新shell中运行程序。

我可以通过以下所有方式启动程序而不会出现DLL错误:

  • 所有文件C:\Tools\axis2c-x86-google\lib\*.dllMath.exe
  • 位于同一目录中
  • 将所有文件C:\Tools\axis2c-x86-google\lib\*.dll放在C:Windows\SysWOW64
  • 在我之前运行的shell窗口中:set PATH=%PATH%;C:\path\to\my\axis2c-x86-google\lib
  • 在我将C:\path\to\my\axis2c-x86-google\lib添加到PATH环境后的新shell中 高级系统设置中的变量。

如果它们都不适合你,那么我担心这个问题超出了我的范围:(

相关问题