Linking CXX executable

4.4k views Asked by At

I try to build progect. When I make ./build.sh -arch x64 I get a linking error:

Linking CXX shared library /home/buzanova/gmat/application/bin/libGmatBase.so [72%] Built target GmatBase Linking CXX executable /home/buzanova/gmat/application/bin/gmatConsole /home/buzanova/gmat/application/bin/libGmatBase.so.R2013a: undefined reference to DelaL::DelaL(std::string const&, GmatBase*) etc.....

My CMakeFile.txt contain

if (UNIX)
MESSAGE("-- Using a shared base library")
IF(APPLE) # mac
    SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -dylib -dynamiclib -two_levelnamespace -undefined dynamic_lookup")

    # snow leopard
    #SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -arch i386")
endif()
endif (UNIX)
INCLUDE_DIRECTORIES("./include")
INCLUDE_DIRECTORIES("./foundation")
INCLUDE_DIRECTORIES("./hardware")
etc......
SET(BASE_SRCS
    asset/AssetException.cpp
    asset/BodyFixedPoint.cpp
    asset/GroundstationInterface.cpp
etc...
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../../application/bin")

ADD_LIBRARY(${TargetName} SHARED ${BASE_SRCS})

How can I fix it?

1

There are 1 answers

0
Pandrei On

for static libraries you need to add some linker flags:

-L<lib_path> -l:<lib_name>

Here's an example( assume that dir myLib is ins the same directory as the makefile):

STATIC_LIBS = -L$(CURDIR)/myLib -l:myLib.a
all: $(EXECUTABLE) 

$(EXECUTABLE): $(OBJ) 
    $(CC) $(LDFLAGS) $(OBJ) $(STATIC_LIBS) -o $@  
.c.o:
    $(CC) $(CFLAGS)  -o $@ $<

clean:
    $(RM) $(EXECUTABLE) $(OBJ)  make.out