Undefined References
Hi,
I'm trying to compile Write-Example.cpp but it fails with the following error messages.
$ g++ main.cpp
/usr/bin/ld: /tmp/cce50VeC.o: in function `main':
main.cpp:(.text+0x61): undefined reference to `Vector::BLF::File::File()'
/usr/bin/ld: main.cpp:(.text+0x86): undefined reference to `Vector::BLF::File::open(char const*, std::_Ios_Openmode)'
/usr/bin/ld: main.cpp:(.text+0x95): undefined reference to `Vector::BLF::File::is_open() const'
/usr/bin/ld: main.cpp:(.text+0xe3): undefined reference to `Vector::BLF::CanMessage::CanMessage()'
/usr/bin/ld: main.cpp:(.text+0x152): undefined reference to `Vector::BLF::File::write(Vector::BLF::ObjectHeaderBase*)'
/usr/bin/ld: main.cpp:(.text+0x161): undefined reference to `Vector::BLF::File::close()'
/usr/bin/ld: main.cpp:(.text+0x175): undefined reference to `Vector::BLF::File::~File()'
/usr/bin/ld: main.cpp:(.text+0x1a0): undefined reference to `Vector::BLF::File::~File()'
collect2: error: ld returned 1 exit status
I'm using gcc (Debian 8.3.0-6) 8.3.0
and cmake version 3.13.4
The output of uname -a
is Linux mx 4.19.0-6-amd64 #1 SMP Debian 4.19.67-2+deb10u2 (2019-11-11) x86_64 GNU/Linux
Any idea what's going wrong?
Regards, Soeren
Comments (7)
-
repo owner -
repo owner -
assigned issue to
- marked as task
- marked as trivial
-
assigned issue to
-
Hi Tobias,
Thanks for you quick reply. I think my original post was a bit misleading due to a typo. I meant that I’m trying to compile using ‘''g++ Write-Example.cpp’'' (not main.cpp). Regarding the installation of Vector_BLF, I followed the instructions in README.md i.e. cmake, make, make install, etc.
Do I need to link to Vector_BLF when I compile Write-Example.cpp e.g. g++ -lVector_BLF or anything like that?
Apologies for the trivial questions. I am new to this stuff…
Thanks,
Soeren
-
So I just tried my own idea of compiling with
g++ -lVector_BLF Write-Example.cpp
So the compilation appears to finish without errors, but when I run the resulting executable (./a.out), I get the following error
./a.out: error while loading shared libraries: libVector_BLF.so.2: cannot open shared object file: No such file or directory
-
Me again…
So everything seems to work now after running.
ldconfig
-
repo owner That’s great to hear. Then you found the solution, faster than me
Bye
Tobias
-
repo owner - changed status to resolved
Linker issue solved.
- Log in to comment
Hi Soeren,
yes, sure. Calling “g++ main.cpp” will build the main.o and try to link it to an executable. But as you gave no instructions to what to link too and also haven’t compiled all the other files, this is not gonna work.
Can you try to follow the instructions in README.md, so ideally using cmake to compile everything? cmake will run the compiler/linker commands in the appropriate order.
Bye
Tobias