-1

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?

Sebastian Mach
  • 38,570
  • 8
  • 95
  • 130
Vika
  • 153
  • 3
  • 4
  • 12
  • 1
    What have you found out about linker errors? – Sebastian Mach Nov 13 '14 at 10:29
  • possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Sebastian Mach Nov 13 '14 at 10:31

1 Answers1

0

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
Pandrei
  • 4,843
  • 3
  • 27
  • 44