|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
problems building an executable with g++
Hello,
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: executable: so $(CXX) $(DEFINES) $(INCLUDES) -L$(LIB_DIR) \ $(SRC_DIR)/executable.cpp \ -o $(BIN_DIR)/executable so: $(CXX) $(DEFINES) $(INCLUDES) -L$(LIB_DIR) -G \ $(SRC_DIR)/module1.cpp \ $(SRC_DIR)/module2.cpp \ ... etc -o $(LIB_DIR)/myobject.so "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. |
|
#2
|
|||
|
|||
|
correction: "make executable", not "make test" is the command in question.
|
|
#3
|
||||
|
||||
|
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:
executable: so $(CXX) $(DEFINES) $(INCLUDES) -L$(LIB_DIR) -lmyobject.so \ $(SRC_DIR)/executable.cpp \ -o $(BIN_DIR)/executable 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): Quote:
EDIT: 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): Quote:
Last edited by dwise1_aol : June 26th, 2003 at 12:03 PM. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > C Programming > problems building an executable with g++ |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|