How to link with chart director library with mingw

395 views Asked by At

I am trying to build an application under mingw with Chart Director. My code compiles fine, but I get undefined reference errors from the linker.

The object file needs to link with ../ChartDirector.cpp/lib/chartdir51.lib

I have renamed this file to ../ChartDirector.cpp/lib/libchartdir51.a If I do not do this the linker cannot find it.

The result is:

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

To make things simpler, I changed to trying to build the simplebar demo application supplied by Chart Director. The build command now looks like this:

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

I still have the same undefineds.

Following this recipe I created a def file looking like this

EXPORTS
Box2DrawObj
TextBox2Box
CBaseChart_destroy
CBaseChart_makeChart
CAxis_setLabels
BarLayer2Layer
CXYChart_create
XYChart2BaseChart
CXYChart_xAxis
CXYChart_setPlotArea
CXYChart_addBarLayer

and used the dlltool to create a new 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

Well that fixed the undefined I saw before, but now I am getting something even more mysterious:

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

I tried downloading the linux version of chartdir. The result was:

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
2

There are 2 answers

0
ravenspoint On BEST ANSWER

The problem was that I was trying to build with a 64 bit version of ChartDirector on a 32 bit mingw. Downloading the 32 bit library fixes the problem:

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
0
J L P J On

Normally undefined reference errors comes when the libs are not matching. Always get the latest libs from ChartDirector download page.