我一直在尝试编译和链接一个用c编写的测试文件,它可以与JModelica的FMILibrary进行通信。我能够编译和链接它,并在linux系统中运行它。在Windows上,我使用了mingw-64编译器来编译测试文件并将其与FMILibrary链接起来,但是我得到了未定义的引用错误。我可以在32位的mingw上编译和运行它,但我需要用64位编译的二进制文件来编译和链接它。
我的命令是这样的:
gcc -I <..fmilib\include> -L <..fmilib\lib> -lfmilib -o testfile testfile.c fmivars.c 下面是结果打印出来的结果
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x9b): undefined reference to `__imp_fmi2_import_get_real'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0xd6): undefined reference to `__imp_fmi2_import_get_integer'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x111): undefined reference to `__imp_fmi2_import_get_boolean'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x14c): undefined reference to `__imp_fmi2_import_get_string'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x187): undefined reference to `__imp_fmi2_import_set_real'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x1c2): undefined reference to `__imp_fmi2_import_set_integer'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x1fd): undefined reference to `__imp_fmi2_import_set_boolean'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x238): undefined reference to `__imp_fmi2_import_set_string'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x27a): undefined reference to `__imp_fmi2_import_new_discrete_states'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x2b6): undefined reference to `__imp_fmi2_import_collect_model_counts'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x30b): undefined reference to `__imp_fmi2_status_to_string'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x37e): undefined reference to `__imp_jm_vsnprintf'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x395): undefined reference to `__imp_fmi2_status_to_string'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x437): undefined reference to `__imp_jm_vsnprintf'
C:\Users\....\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x556): undefined reference to `__imp_fmi2_import_get_version'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x575): undefined reference to `__imp_fmi2_import_get_types_platform'
C:\Users\....\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x594): undefined reference to `__imp_fmi2_import_get_number_of_continuous_states'
C:\Users\...\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x5a8): undefined reference to `__imp_fmi2_import_get_number_of_event_indicators'
C:\Users\....\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x64a): undefined reference to `__imp_fmi2_import_instantiate'
C:\Users\....\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x690): undefined reference to `__imp_fmi2_import_set_debug_logging'
C:\Users\....\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x6af): undefined reference to `__imp_fmi2_status_to_string'
C:\Users\....\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x6df): undefined reference to `__imp_fmi2_import_set_debug_logging'
C:\Users\....\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x718): undefined reference to `__imp_fmi2_import_setup_experiment'
C:\Users\....\AppData\Local\Temp\ccFR53Q1.o:testfile.c:(.text+0x733): undefined reference to `__imp_fmi2_import_enter_initialization_mode'是否有任何宏或FMILibrary上的任何设置,以编译与64位明文在windows 64位上的编译器?谢谢。
发布于 2019-02-02 18:04:28
假设库libfmilib.x.y.z提供了缺少的符号,那么在链接器的/编译器的命令行上,将它移到需要它们的.c文件的右侧
gcc -I <..fmilib\include> -L <..fmilib\lib> -o testfile testfile.c fmivars.c -lfmilib 发布于 2019-02-05 22:15:42
谢谢大家帮助我。我终于解决了我的问题,并且能够运行代码了。我按照@PilouPili的建议安装了dependency walker,发现我的应用程序正在同一文件夹中查找该库(出于某种原因,我不知道),但它找不到它。所以,我复制了所有的静态库和动态库,并粘贴到了我的testfile所在的文件夹中。我还按照@alk的建议更改了命令行,并将-lfmilib移到了末尾。我使用的是动态库,而不是静态库。但不管怎样,我的应用程序现在可以运行了。非常感谢你的帮助。
https://stackoverflow.com/questions/54485280
复制相似问题