链接CXX可执行文件



我尝试构建proect。当我做的时候/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})

我该怎么修?

对于静态库,您需要添加一些链接器标志:

-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

相关内容

  • 没有找到相关文章

最新更新