June 26th, 2003, 10:11 AM
problems building an executable with g++
I'm trying to compile by C++ code into a shared object and
then create an executable that would use functions from
that shared object.
The SO build works fine.
The compilation of the executable is what is giving me problems. My makefile looks like this:
$(CXX) $(DEFINES) $(INCLUDES) -L$(LIB_DIR) \
$(CXX) $(DEFINES) $(INCLUDES) -L$(LIB_DIR) -G \
"make so" works fine, it generates the file myobject.so in the directory $(LIB_DIR). But when I do "make test", I get an error
like "Undefined symbol..first referenced in the file..". But that symbol was defined in one of the modules. I would think that it would be now available from the myobject.so file which is used by the task "executable". Why wouldn't it see the symbol?
Anybody have any idea?
Thanks in advance.
June 26th, 2003, 10:13 AM
correction: "make executable", not "make test" is the command in question.
June 26th, 2003, 11:51 AM
My book's not clear on that ("Beginning Linux Programming" 2nd ed., Stones and Matthew), but it looks like you need to name the shared library in the call to gcc:
$(CXX) $(DEFINES) $(INCLUDES) -L$(LIB_DIR) -lmyobject.so \
What I'm not clear on is whether you need to give the .so extension or not. The books gives an example that links in library foo and says (pg 21):
Your make so looked like you were creating an executable instead of a library, so I checked my notes from my other book (at home -- "Linux Programming by Example" by Kurt Wall):
Last edited by dwise1_aol; June 26th, 2003 at 12:03 PM.