我正在尝试使用Chart Director在mingw下构建一个应用程序。我的代码编译得很好,但我从链接器中获得了未定义的引用错误。
目标文件需要链接到../ ChartDirector.cpp / lib / chartdir51.lib
我已将此文件重命名为../ChartDirector.cpp/lib/libchartdir51.a如果我不这样做,则链接器无法找到它。
结果是:
mingw32-g++.exe -LJ:\wxWidgets-3.0.1\lib\gcc481TDM_dll
-L..\ChartDirector_cpp\lib -o ..\bin\plot.exe obj\Debug\plot.o
-lwxbase30u -lwxmsw30u_core -lchartdir51 -mwindows
obj\Debug\plot.o: In function `ZN3BoxC2EP11BoxInternal':
C:\Users\James\Documents\code\vase\plot/../ChartDirector_cpp/include/chartdir.h:804:
undefined reference to `Box2DrawObj'
obj\Debug\plot.o: In function `ZN7TextBoxC1EP15TextBoxInternal':
C:\Users\James\Documents\code\vase\plot/../ChartDirector_cpp/include/chartdir.h:832:
undefined reference to `TextBox2Box'
... and so on
为了简单起见,我改为尝试构建Chart Director提供的simplebar演示应用程序。 build命令现在看起来像这样:
mingw32-g++.exe
C:\Users\James\Documents\code\vase\test\simplebar.cpp
-IC:\Users\James\Documents\code\vase\ChartDirector_cpp\include
-o C:\Users\James\Documents\code\vase\bin\test.exe
-LC:\Users\James\Documents\code\vase\ChartDirector_cpp\lib\
-lchartdir51
我仍然有相同的未定义。
关注this recipe我创建了一个看起来像这样的def文件
EXPORTS
Box2DrawObj
TextBox2Box
CBaseChart_destroy
CBaseChart_makeChart
CAxis_setLabels
BarLayer2Layer
CXYChart_create
XYChart2BaseChart
CXYChart_xAxis
CXYChart_setPlotArea
CXYChart_addBarLayer
并使用dlltool创建一个新的libchartdir51.a
dlltool -d C:\Users\James\Documents\code\vase\ChartDirector_cpp\lib\chartdir.def
-l C:\Users\James\Documents\code\vase\ChartDirector_cpp\lib\libchartdir51.a
那就修好了我之前看过的未定义,但现在我得到的东西更加神秘了:
C:\Users\James\Documents\code\vase\ChartDirector_cpp\lib/libchartdir51.a(diaybs00001.o):(.idata$7+0x
0):
undefined reference to `_head_C__Users_James_Documents_code_vase_ChartDirector_cpp_lib_libchartd
ir51_a'
C:\Users\James\Documents\code\vase\ChartDirector_cpp\lib/libchartdir51.a(diaybs00009.o):(.idata$7+0x
0): undefined reference to `_head_C__Users_James_Documents_code_vase_ChartDirector_cpp_lib_libchartd
ir51_a'
... and so on
我尝试下载mapdir的linux版本。结果是:
mingw32-g++.exe
C:\Users\James\Downloads\ChartDirector\cppdemo\simplebar\simplebar.cpp
-IC:\Users\James\Downloads\ChartDirector\include
-o C:\Users\James\code\vase\bin\test.exe
C:\Users\James\Downloads\ChartDirector\lib\libchartdir.so.5.1.0
C:\Users\James\Downloads\ChartDirector\lib\libchartdir.so.5.1.0:
could not read symbols: File in wrong format
collect2.exe: error: ld returned 1 exit status
答案 0 :(得分:1)
当库不匹配时,通常会出现未定义的参考错误。始终从ChartDirector下载页面获取最新的库。
答案 1 :(得分:0)
问题是我试图在32位mingw上使用64位版本的ChartDirector构建。下载32位库可以解决问题:
mingw32-g++
C:\Users\James\Downloads\chartdir_cpp_win32\ChartDirector\cppdemo\simplebar\simplebar.cpp
-IC:\Users\Jam es\Downloads\chartdir_cpp_win32\ChartDirector\include
-o C:\Users\James\code\vase\bin\test2.exe
-C:\Users\James\Downloads\chartdir_cpp_win32\ChartDirector\lib\chartdir51.dll