|
[Sponsors] |
June 29, 2018, 00:37 |
Undefined reference to custom class
|
#1 |
Senior Member
Ruiyan Chen
Join Date: Jul 2016
Location: Hangzhou, China
Posts: 162
Rep Power: 10 |
Hi Guys,
I developed a class of my own named testPdfTable. I had both the .H file and .C file written, then I used wmake libso to compile it. The compilation runs smooth without any errors, and a .so file named libtestPdfTable.so is generated without any problem. After this I wrote a simple program (Test-pdf.C) to test the above class. The Make/files file looks like the following Code:
Test-pdf.C EXE = $(FOAM_USER_APPBIN)/Test-pdf Code:
EXE_INC = \ -I$(realpath ../../myThermoModels/basic/testPdfTable/lnInclude) \ LIB_LIBS = \ -L$(FOAM_USER_LIBBIN) \ -ltestPdfTable When I run wmake the compiler gives me the following error message Code:
Making dependency list for source file Test-pdf.C g++ -std=c++0x -m64 -Dlinux64 -DWM_ARCH_OPTION=64 -DWM_DP -DWM_LABEL_SIZE=32 -Wall -Wextra -Wold-style-cast -Wnon-virtual-dtor -Wno-unused-parameter -Wno-invalid-offsetof -O3 -DNoRepository -ftemplate-depth-100 -I/home/ruiyan/OpenFOAM/ruiyan-4.x/myThermoModels/basic/testPdfTable/lnInclude -IlnInclude -I. -I/home/ruiyan/OpenFOAM/OpenFOAM-4.x/src/OpenFOAM/lnInclude -I/home/ruiyan/OpenFOAM/OpenFOAM-4.x/src/OSspecific/POSIX/lnInclude -fPIC -c Test-pdf.C -o Make/linux64GccDPInt32Opt/Test-pdf.o g++ -std=c++0x -m64 -Dlinux64 -DWM_ARCH_OPTION=64 -DWM_DP -DWM_LABEL_SIZE=32 -Wall -Wextra -Wold-style-cast -Wnon-virtual-dtor -Wno-unused-parameter -Wno-invalid-offsetof -O3 -DNoRepository -ftemplate-depth-100 -I/home/ruiyan/OpenFOAM/ruiyan-4.x/myThermoModels/basic/testPdfTable/lnInclude -IlnInclude -I. -I/home/ruiyan/OpenFOAM/OpenFOAM-4.x/src/OpenFOAM/lnInclude -I/home/ruiyan/OpenFOAM/OpenFOAM-4.x/src/OSspecific/POSIX/lnInclude -fPIC -Xlinker --add-needed -Xlinker --no-as-needed Make/linux64GccDPInt32Opt/Test-pdf.o -L/home/ruiyan/OpenFOAM/OpenFOAM-4.x/platforms/linux64GccDPInt32Opt/lib \ -lOpenFOAM -ldl \ -lm -o /home/ruiyan/OpenFOAM/ruiyan-4.x/platforms/linux64GccDPInt32Opt/bin/Test-pdf Make/linux64GccDPInt32Opt/Test-pdf.o: In function `main': Test-pdf.C:(.text.startup+0x5a): undefined reference to `Foam::testPdfTable::testPdfTable()' Test-pdf.C:(.text.startup+0x62): undefined reference to `Foam::testPdfTable::ReadPDF()' Test-pdf.C:(.text.startup+0xf3): undefined reference to `Foam::testPdfTable::interpolate(int, double) const' Test-pdf.C:(.text.startup+0x1cb): undefined reference to `Foam::testPdfTable::interpolate(int, double) const' Test-pdf.C:(.text.startup+0x2b4): undefined reference to `Foam::testPdfTable::~testPdfTable()' Test-pdf.C:(.text.startup+0x304): undefined reference to `Foam::testPdfTable::~testPdfTable()' collect2: error: ld returned 1 exit status /home/ruiyan/OpenFOAM/OpenFOAM-4.x/wmake/makefiles/general:132: recipe for target '/home/ruiyan/OpenFOAM/ruiyan-4.x/platforms/linux64GccDPInt32Opt/bin/Test-pdf' failed make: *** [/home/ruiyan/OpenFOAM/ruiyan-4.x/platforms/linux64GccDPInt32Opt/bin/Test-pdf] Error 1 EDIT: I compiled the class and the test function using gcc on Linux system. It worked pretty well. So my problem is more likely to be a linking issue in OF. What could be the problem and how can this be fixed? Thank you guys in advance. BTW I'm running OF-4.x on a virtual machine using Ubuntu. Last edited by cryabroad; July 2, 2018 at 03:17. |
|
June 29, 2018, 03:22 |
|
#2 |
Senior Member
Yan Zhang
Join Date: May 2014
Posts: 120
Rep Power: 12 |
It seems that you just declare these functions in .H but not defined them in .C
__________________
https://openfoam.top |
|
July 1, 2018, 23:43 |
|
#3 |
Senior Member
Ruiyan Chen
Join Date: Jul 2016
Location: Hangzhou, China
Posts: 162
Rep Power: 10 |
Hi Zhangyan,
Thank you for the suggestions. I've double checked to make sure that the functions are both declared and defined. I actually compiled the class (.H and .C) and the main function Test-pdf.C using the build-in gcc compiler for Linux system. The program runs pretty well. I will add the above info to my original post so people can have a better idea of what I've done. Thank you again. |
|
July 2, 2018, 22:19 |
|
#4 |
Senior Member
Yan Zhang
Join Date: May 2014
Posts: 120
Rep Power: 12 |
Have you solved this issue? I met the same problem...
__________________
https://openfoam.top |
|
July 3, 2018, 01:56 |
|
#5 |
Senior Member
Yan Zhang
Join Date: May 2014
Posts: 120
Rep Power: 12 |
Maybe I found a solution for your problem:
In the solver's options file, it should have a EXE_LIBS, instead of LIB_LIBS.
__________________
https://openfoam.top |
|
July 3, 2018, 03:21 |
|
#6 |
Senior Member
Ruiyan Chen
Join Date: Jul 2016
Location: Hangzhou, China
Posts: 162
Rep Power: 10 |
Dear Zhangyan,
It really works! I've never noticed that this part of code is that important. After all it all makes sense now: when we compile to create libraries, we use EXE_INC for including other header files, and LIB_LIBS for including other libraries; when we compile to get executable files, we change LIB_LIBS to EXE_LIBS. This is clearly shown in OF source code, the Make file for libraries are paired with EXE_INC and LIB_LIBS, and the Make file for solvers are paired with EXE_INC and EXE_LIBS. I should've noticed that earlier, feel so stupid right now. I wonder if the EXE_INC is also changeable. Thank you for your help, really appreciate it! |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
-Xlinker --add-needed -Xlinker --no-as-needed | NH1994 | OpenFOAM Programming & Development | 7 | December 31, 2014 11:24 |
openFoam-1.7.x installation | Roman1 | OpenFOAM Installation | 4 | October 2, 2013 09:02 |
Reynolds Stress Custom BC | maninthemail | OpenFOAM | 3 | November 14, 2011 14:58 |
OpenFoam 1.6-ext - RPM build errors | preibie | OpenFOAM | 12 | September 8, 2011 04:12 |
OF Successfully built? | Pytthon | OpenFOAM | 5 | February 20, 2010 07:44 |