-6

When I've try to compile program (test for my lib) I've got undefined reference of for every called method. I've read answers on "gcc undefined reference to", but it has not help. PS I using: Debian 7.2.0 and C++11 standart.

#include <RFw/String.hpp>
#include <stdio.h>
using namespace RFw;

int main() {
Array<char> _arr_ (5);

_arr_[0] = 'b';
_arr_[1] = 'c';

printf("%c%c\n", _arr_[0], _arr_[2]);

printf(RFw::getVersion());

return 0;
}

Makefile target:

test:
    c++ test.cpp -I./include-core/ -o bin/test -L./bin -l${core_NAME_ROOT}

Console output:

test.cpp:13:9: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
        printf(RFw::getVersion());
               ^~~~~~~~~~~~~~~~~
1 warning generated.
/tmp/test-lxdZF4.o: In function `main':
test.cpp:(.text+0x20): undefined reference to `RFw::Array<char>::Array(int)'
test.cpp:(.text+0x33): undefined reference to `RFw::Array<char>::operator[](int)'
test.cpp:(.text+0x54): undefined reference to `RFw::Array<char>::operator[](int)'
test.cpp:(.text+0x75): undefined reference to `RFw::Array<char>::operator[](int)'
test.cpp:(.text+0x99): undefined reference to `RFw::Array<char>::operator[](int)'
test.cpp:(.text+0xff): undefined reference to `RFw::Array<char>::~Array()'
test.cpp:(.text+0x11a): undefined reference to `RFw::Array<char>::~Array()'
./bin/libregemfw0.1-core.so: undefined reference to `RFw::Array<char>::operator[](int) const'
./bin/libregemfw0.1-core.so: undefined reference to `RFw::Array<char>::Array(int)'
./bin/libregemfw0.1-core.so: undefined reference to `RFw::Array<char>::getLength() const'
./bin/libregemfw0.1-core.so: undefined reference to `RFw::Exception::onThrow()'
./bin/libregemfw0.1-core.so: undefined reference to `RFw::Array<char>::resize(int)'
./bin/libregemfw0.1-core.so: undefined reference to `RFw::Array<char>::addElementOnEnd(char)'
./bin/libregemfw0.1-core.so: undefined reference to `vtable for RFw::Object'
./bin/libregemfw0.1-core.so: undefined reference to `typeinfo for RFw::Object'
./bin/libregemfw0.1-core.so: undefined reference to `RFw::Object::~Object()'
./bin/libregemfw0.1-core.so: undefined reference to `RFw::Array<char>::~Array()'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [test] Ошибка 1
5
  • You're going to have to provide a lot more information if you want helpful answers. What's the code you're trying to compile? What are the specific error messages you're getting? Nov 4, 2013 at 10:28
  • You don't show the code, you don't show the command line you use and you don't show the error message you get. How on earth do expect anyone to be able to help??? Nov 4, 2013 at 10:29
  • Please show the code bro so we can help easily :) else you will have bunch of downvotes from the helpers Nov 4, 2013 at 10:30
  • Put the compiler argument test.cpp before the -l... argument.
    – leemes
    Nov 4, 2013 at 10:45

1 Answer 1

2

The problem is that

c++ test.cpp -I./include-core/ -o bin/test -L./bin -l${core_NAME_ROOT}c++ test.cpp -I./include-core/ -o bin/test -L./bin -l${core_NAME_ROOT}

will first process the library and then your .cpp file. When processing a library, referenced symbols are resolved ("linked") and all unresolved symbols in the library that aren't needed are thrown away. That means that as soon as your .cpp file is being processed, these symbols are already rejected. You have the library twice in your command line, but the second one is being ignored since the library was already processed.

You should always put the libraries (once) at the end of the compiler command line:

c++ test.cpp -I./include-core/ -o bin/test test.cpp -L./bin -l${core_NAME_ROOT}
2
  • That second part of his command looks wrong -- almost like he ctrl-v one too many times.
    – greatwolf
    Nov 4, 2013 at 10:55
  • Well I also thought this, but I guess the OP might have tried to solve it by just appending the libraries again.
    – leemes
    Nov 4, 2013 at 11:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.