无法链接OSX travis映像中的brew installde CPPFUnit 我在Github上有一个基于CGED的C++项目,它与Travis CI一起构建。.travis.yml文件在OSX上构建时具有以下特性: language: cpp jobs: include: - os: osx compiler: gcc osx_image: xcode11.2 env: - GCC_VER="9" - MATRIX_EVAL="CC=gcc-${GCC_VER} && CXX=g++-${GCC_VER}" addons: homebrew: packages: - cppunit - mruby ... (other OS) ... before_script: - eval "${MATRIX_EVAL}" script: - cmake -D ENABLE_TESTS:BOOL=TRUE . - cmake --build . -- -j2 - ctest -j2

无法链接OSX travis映像中的brew installde CPPFUnit 我在Github上有一个基于CGED的C++项目,它与Travis CI一起构建。.travis.yml文件在OSX上构建时具有以下特性: language: cpp jobs: include: - os: osx compiler: gcc osx_image: xcode11.2 env: - GCC_VER="9" - MATRIX_EVAL="CC=gcc-${GCC_VER} && CXX=g++-${GCC_VER}" addons: homebrew: packages: - cppunit - mruby ... (other OS) ... before_script: - eval "${MATRIX_EVAL}" script: - cmake -D ENABLE_TESTS:BOOL=TRUE . - cmake --build . -- -j2 - ctest -j2,c++,macos,cmake,travis-ci,cppunit,C++,Macos,Cmake,Travis Ci,Cppunit,CPPU单元由brew安装 cmake命令运行正常,并在/usr/local(即,CPPUNIT\u INDLUE\u DIR被正确设置为/usr/local/include,而CPPUNIT\u库被正确设置为/usr/local/lib/libcppunit.dylib。但是,在构建测试时,我得到与CPPUNIT相关的未定义符号的链接错误,表明它没有正确地链接到CPPUNIT。 同样的项目可以在我的MacBook上很好地构建(也安装了brew的CPPFUnit),并且可以在Linux上正确地构

CPPU单元由
brew
安装

cmake命令运行正常,并在
/usr/local
(即,
CPPUNIT\u INDLUE\u DIR
被正确设置为
/usr/local/include
,而
CPPUNIT\u库
被正确设置为
/usr/local/lib/libcppunit.dylib
。但是,在构建测试时,我得到与CPPUNIT相关的未定义符号的链接错误,表明它没有正确地链接到CPPUNIT。

同样的项目可以在我的MacBook上很好地构建(也安装了brew的CPPFUnit),并且可以在Linux上正确地构建gcc-9和clang,通过apt安装了CPPFUnit

我想我需要在某个地方设置
DYLD\u LIBRARY\u PATH=$DYLD\u LIBRARY\u PATH:/usr/local/lib
,但当我这样做时,会出现新的错误:

$ cmake -D ENABLE_TESTS:BOOL=TRUE .

dyld: Symbol not found: __cg_jpeg_resync_to_restart

  Referenced from: /System/Library/Frameworks/ImageIO.framework/Versions/A/ImageIO

  Expected in: /usr/local/lib/libJPEG.dylib

 in /System/Library/Frameworks/ImageIO.framework/Versions/A/ImageIO

/Users/travis/.travis/functions: line 109:  3565 Abort trap: 6           cmake -D ENABLE_TESTS:BOOL=TRUE .

The command "cmake -D ENABLE_TESTS:BOOL=TRUE ." exited with 134.
以下是源文件根目录下的CMakeLists.txt文件:

cmake_minimum_required (VERSION 3.1)
project (mrbind17 CXX)

set (CMAKE_CXX_STANDARD 17)

set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
     "${CMAKE_CURRENT_SOURCE_DIR}/cmake")


add_definitions(-g)
option(ENABLE_TESTS "Build tests. May require CppUnit_ROOT" OFF)

include_directories (${CMAKE_CURRENT_SOURCE_DIR}/include)

find_package (Mruby REQUIRED)
include_directories (${Mruby_INCLUDE_DIR})

find_package (CppUnit)
if (CPPUNIT_FOUND)
    message(STATUS "CppUnit found, unit tests will be compiled")
    message(STATUS "CPPUNIT_INCLUDE_DIR : ${CPPUNIT_INCLUDE_DIR}")
    message(STATUS "CPPUNIT_LIBRARIES : ${CPPUNIT_LIBRARIES}")
    include_directories(${CPPUNIT_INCLUDE_DIR})
    enable_testing()
    if(${ENABLE_TESTS})
        add_subdirectory (test)
    endif(${ENABLE_TESTS})
else (CPPUNIT_FOUND)
    message(STATUS "CppUnit not found, unit tests will not be compiled")
endif (CPPUNIT_FOUND)
以及测试目录中的CMakeLists.txt:

add_executable(interpreter_test main.cpp interpreter_test.cpp)
target_link_libraries(interpreter_test ${Mruby_LIBRARIES} ${CPPUNIT_LIBRARIES})
add_test(NAME interpreter_test COMMAND ./interpreter_test interpreter_test.xml)

add_executable(function_test main.cpp function_test.cpp)
target_link_libraries(function_test ${Mruby_LIBRARIES} ${CPPUNIT_LIBRARIES})
add_test(NAME function_test COMMAND ./function_test function_test.xml)

add_executable(module_test main.cpp module_test.cpp)
target_link_libraries(module_test ${Mruby_LIBRARIES} ${CPPUNIT_LIBRARIES})
add_test(NAME module_test COMMAND ./module_test module_test.xml)

如何使cmake链接正确地与CPPFUnit相对应?

请在问题帖子中显示cmake代码,而不是描述您的cmake文件?当然,我添加了它。您可以在问题帖子中显示cmake代码,而不是描述您的cmake文件吗?当然,我添加了它。