Reputation: 184
I need some help with C++ compilation, as I'm obviously missing something.
I've created .so library (let's call it mylib) depending on other .so library I wrote (mylib2) and some simple program using it. Also the second library depends on ANTLR. I use CMake for building both libs and they are compiling and installing just fine. But when I try to compile the program:
cmd> g++ program.cpp -lmylib
I get
/usr/local/lib/libmylib2.so.0: undefined reference to `antlr::CharScanner::traceOut(char const*)'
ANTLR appears to be static lib, so I tried
cmd> g++ program.cpp -lmylib -Wl,-Bstatic -lantlr
But then all I get is
/usr/bin/ld: cannot find -lgcc_s
I've got two questions here:
1) Why can't mylib2 see antlr? I should mention, that I use my own cmake find script, can this be a problem?
find_package(ANTLR REQUIRED)
include_directories(${ANTLR_INCLUDE_DIR})
2) What does the second error mean? Why can't ld find libgcc_s?
I will really appreciate any help.
EDIT
I should mention I am using ANTLR 2.7
Upvotes: 0
Views: 1143
Reputation: 17455
From man ld
(GNU ld): -Bstatic
- Do not link against shared libraries. You may use this option multiple times on the command line: it affects library searching for -l options which follow it. So you should manually enable using dynamic libraries after -lantlr
. Please remember, that linking a static library not being compiled with -fPIC
option may result in non-relocatable code and longer application startup time http://www.airs.com/blog/archives/41
Upvotes: 1