我尝试建立progect。当我制作./build.sh -arch x64时,我收到一个链接错误:
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.....
我的CMakeFile.txt包含
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})
我该如何解决?
答案 0 :(得分:0)
对于静态库,您需要添加一些链接器标志:
-L<lib_path> -l:<lib_name>
这是一个例子(假设dir myLib与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