Dealing with undefined reference to ''

Hi All,
I am trying to compile the Example_TQ.cpp file as mentioned in https://github.com/sundmanbo/opencalphad/tree/version3/TQ3lib-clean/isoC-Sigli, with the following commands discussed in the linkpm.txt therein:
1
2
3
4
5
6
7
8
9
copy ..\..\liboceq.a .

copy ..\..\liboceqplus.mod .

gfortran -c liboctq.F90

gfortran -c liboctqisoc.F90

g++ -o sigli -fopenmp -lstdc++ Example_TQ.cpp liboctqisoc.o liboctq.o liboceq.a -lgfortran -lm


The two files are first copied to the given directory. and, then the commands are typed. The fortran compilation is successful. Then the portion of message displayed in the terminal of Ubuntu 14.04 computer for g++ compilation is:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
...
$ g++ -o sigli  -lstdc++ Example_TQ.cpp liboctqisoc.o liboctq.o liboceq.a -lgfortran -lm
...
liboctq.F90:(.text+0x45a8): multiple definition of `__liboctq_MOD_tqini'
liboctqisoc.o:liboctqisoc.F90:(.text+0x45a8): first defined here
/tmp/ccjUVqhn.o: In function `Get_Ceq(int const&, void*)':
Example_TQ.cpp:(.text+0x20): undefined reference to `c_selecteq'
/tmp/ccjUVqhn.o: In function `Initialize(void*)':
Example_TQ.cpp:(.text+0x4e): undefined reference to `c_tqini'
/tmp/ccjUVqhn.o: In function `Create_New_Ceq_and_Return_ID(std::string const&)':
Example_TQ.cpp:(.text+0xad): undefined reference to `c_newEquilibrium'
/tmp/ccjUVqhn.o: In function `Get_Ceq_pointer(int const&, void*)':
Example_TQ.cpp:(.text+0xe2): undefined reference to `c_selecteq'
/tmp/ccjUVqhn.o: In function `GetAllElementsFromDatabase(std::string)':
Example_TQ.cpp:(.text+0x13a): undefined reference to `c_checktdb'
/tmp/ccjUVqhn.o: In function `ReadDatabase(std::string, void*)':
Example_TQ.cpp:(.text+0x1a9): undefined reference to `c_tqrfil'
/tmp/ccjUVqhn.o: In function `ReadDatabaseLimited(std::string&, std::vector<std::string, std::allocator<std::string> >&, void*)':
Example_TQ.cpp:(.text+0x353): undefined reference to `c_tqrpfil'
/tmp/ccjUVqhn.o: In function `ReadPhases(std::vector<std::string, std::allocator<std::string> >&, void*)':
Example_TQ.cpp:(.text+0x3b5): undefined reference to `c_ntup'
Example_TQ.cpp:(.text+0x3f8): undefined reference to `c_tqgpn'
Example_TQ.cpp:(.text+0x40f): undefined reference to `c_tqgpi'
Example_TQ.cpp:(.text+0x4b8): undefined reference to `c_ntup'
/tmp/ccjUVqhn.o: In function `ResetTemperature(void*)':
Example_TQ.cpp:(.text+0x5bc): undefined reference to `c_reset_conditions'
/tmp/ccjUVqhn.o: In function `ResetAllConditionsButPandN(void*, std::vector<std::string, std::allocator<std::string> > const&, int const&, std::string const&)':
Example_TQ.cpp:(.text+0x6ba): undefined reference to `c_reset_conditions'
Example_TQ.cpp:(.text+0x81f): undefined reference to `c_reset_conditions'
/tmp/ccjUVqhn.o: In function `Change_Phase_Status(std::string const&, int const&, double const&, void*)':
Example_TQ.cpp:(.text+0x976): undefined reference to `c_Change_Status_Phase'
/tmp/ccjUVqhn.o: In function `SetTemperature(double const&, void*)':
Example_TQ.cpp:(.text+0x9fc): undefined reference to `c_tqsetc'
/tmp/ccjUVqhn.o: In function `SetPressure(double const&, void*)':
Example_TQ.cpp:(.text+0xa8a): undefined reference to `c_tqsetc'
/tmp/ccjUVqhn.o: In function `SetMoles(double const&, void*)':
Example_TQ.cpp:(.text+0xb18): undefined reference to `c_tqsetc'
/tmp/ccjUVqhn.o: In function `SetComposition(std::vector<double, std::allocator<double> >&, void*, int const&, std::string&)':
Example_TQ.cpp:(.text+0xc4e): undefined reference to `c_tqsetc'
Example_TQ.cpp:(.text+0xcaa): undefined reference to `c_nel'
/tmp/ccjUVqhn.o: In function `SetConstituents(int, std::vector<double, std::allocator<double> >, void*)':
Example_TQ.cpp:(.text+0xe05): undefined reference to `c_tqsphc1'
/tmp/ccjUVqhn.o: In function `List_Conditions(void*)':
Example_TQ.cpp:(.text+0xf26): undefined reference to `c_List_Conditions'
/tmp/ccjUVqhn.o: In function `CalculateEquilibrium(void*, int const&, int&, std::vector<std::string, std::allocator<std::string> > const&)':
Example_TQ.cpp:(.text+0x1069): undefined reference to `c_tqce'
Example_TQ.cpp:(.text+0x106e): undefined reference to `c_errors_number'
/tmp/ccjUVqhn.o: In function `GetGibbsData(int, void*)':
Example_TQ.cpp:(.text+0x111c): undefined reference to `c_tqcph1'
/tmp/ccjUVqhn.o: In function `ReadPhaseFractions(std::vector<std::string, std::allocator<std::string> > const&, std::vector<double, std::allocator<double> >&, void*)':
Example_TQ.cpp:(.text+0x14c1): undefined reference to `c_tqgetv'
/tmp/ccjUVqhn.o: In function `ReadMU(void*, std::vector<double, std::allocator<double> >&)':
Example_TQ.cpp:(.text+0x15cc): undefined reference to `c_tqgetv'
Example_TQ.cpp:(.text+0x15f8): undefined reference to `c_nel'
/tmp/ccjUVqhn.o: In function `ReadTemperature(void*)':
Example_TQ.cpp:(.text+0x1691): undefined reference to `c_tqgetv'
/tmp/ccjUVqhn.o: In function `ReadConstituentFractions(std::vector<std::string, std::allocator<std::string> > const&, std::vector<double, std::allocator<double> > const&, std::vector<std::vector<double, std::allocator<double> >, std::allocator<std::vector<double, std::allocator<double> > > >&, void*, std::string const&)':
Example_TQ.cpp:(.text+0x1724): undefined reference to `c_tqgpn'
Example_TQ.cpp:(.text+0x182d): undefined reference to `c_tqgetv'
Example_TQ.cpp:(.text+0x18c7): undefined reference to `c_ntup'
/tmp/ccjUVqhn.o: In function `ListExtConstituentFractions(int, std::vector<std::string, std::allocator<std::string> >, void*)':
Example_TQ.cpp:(.text+0x196b): undefined reference to `c_tqgphc1'
/tmp/ccjUVqhn.o: In function `Find_Transitions(double const&, int const&, double const&, std::vector<double, std::allocator<double> >&, std::vector<std::string, std::allocator<std::string> > const&, std::vector<double, std::allocator<double> >&, std::vector<std::string, std::allocator<std::string> > const&, bool, bool, std::vector<int, std::allocator<int> >&, std::vector<std::string, std::allocator<std::string> >&, void*, double, std::vector<std::string, std::allocator<std::string> > const&)':
Example_TQ.cpp:(.text+0x2713): undefined reference to `c_selecteq'
/tmp/ccjUVqhn.o: In function `Global_Find_Transitions(std::basic_ofstream<char, std::char_traits<char> >&, double&, int const&, double&, double, std::vector<double, std::allocator<double> >&, std::vector<std::string, std::allocator<std::string> > const&, std::vector<std::string, std::allocator<std::string> > const&, void*, int const&, std::string const&, int const&, std::vector<int, std::allocator<int> >&, std::vector<std::string, std::allocator<std::string> >&, std::vector<std::string, std::allocator<std::string> > const&)':
Example_TQ.cpp:(.text+0x3282): undefined reference to `c_selecteq'
Example_TQ.cpp:(.text+0x331a): undefined reference to `c_set_status_globaldata'
/tmp/ccjUVqhn.o: In function `Random_Equilibrium_Loop(double&, double&, std::vector<double, std::allocator<double> >&, std::vector<std::string, std::allocator<std::string> > const&, std::vector<std::string, std::allocator<std::string> > const&, void*, int, std::string const&, int const&, int const&, std::vector<int, std::allocator<int> >&, std::vector<std::string, std::allocator<std::string> >&, std::vector<std::string, std::allocator<std::string> > const&)':
Example_TQ.cpp:(.text+0x3f04): undefined reference to `omp_get_num_procs'
Example_TQ.cpp:(.text+0x40d8): undefined reference to `c_selecteq'
Example_TQ.cpp:(.text+0x4673): undefined reference to `c_selecteq'
/tmp/ccjUVqhn.o: In function `main':
Example_TQ.cpp:(.text+0x6a71): undefined reference to `omp_set_num_threads'
Example_TQ.cpp:(.text+0x70f9): undefined reference to `c_cnam'
Example_TQ.cpp:(.text+0x71ad): undefined reference to `c_nel'
Example_TQ.cpp:(.text+0x7813): undefined reference to `omp_set_num_threads'
Example_TQ.cpp:(.text+0x890f): undefined reference to `c_set_status_globaldata'
collect2: error: ld returned 1 exit status 


Where should i look into the files? Are they related to cpp files or the dependencies namely the compiled fortran files?

Yours Sincerely,
Anil Kunwar
Last edited on
liboctqisoc.o and liboctq.o both appear to define `__liboctq_MOD_tqini', so I suspect you should link in only one.

All the other errors look like a failure to link a particular library. Do the symbols that are undefined look familiar? Whatever library you are using is probably supposed to define them for you.
Hi Zhuge,
After the author has made the following modification in the liboctqisoc.F90, the issue has been resolved.
https://github.com/sundmanbo/opencalphad/commit/4a53645078bd2f5d30a4701e8cfeb72f4667cfce

One of the additions made in liboctqisoc.F90 is
+ nullify(ceq) .
I peeped into the liboctq.F90 and there also, i saw that ceq was defined.
Thank you for your helpful information. Cheers.

Yours Sincerely,
Anil Kunwar
Last edited on
Topic archived. No new replies allowed.