0

我在具有最新操作系统的 macbook 上工作。通过自制软件安装 icu4c 库。但我无法正确链接 libicuuc。在查找库的情况下,我使用

export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/Cellar/icu4c/64.2/lib/pkgconfig

在我的 ~/.bashrc 上,但仍然出现链接错误。

这是一个非常简单的 CMakeLists.txt:

cmake_minimum_required(VERSION 3.4)

project(xeditd CXX)

find_package(PkgConfig REQUIRED)
pkg_search_module(ICU_UC icu-uc)

set(LIB_DIR
    ${ICU_UC_LIBRARY_DIRS}
    )

set(LIB
    ${ICU_UC_LIBRARIES}
    )

set(INC_DIR
    ${ICU_UC_INCLUDE_DIRS}
    )

set(SRC_FILE
    xeditd.cpp
    )

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -o2 ${ICU_UC_CXXFLAGS_OTHER}")

message(${LIB_DIR})
message(${LIB})
message(${INC_DIR})
message(${CMAKE_CXX_FLAGS})

add_executable(xeditd ${SRC_FILE})
link_directories(${LIB_DIR})
target_link_libraries(xeditd ${LIB})
target_include_directories(xeditd PUBLIC ${INC_DIR})

它生成:

/usr/local/Cellar/icu4c/64.2/lib         (${LIB_DIR})
icuucicudata                             (${LIB})
/usr/local/Cellar/icu4c/64.2/include     (${INC_DIR})
-std=c++14 -std=c++14 -o2                (${CMAKE_CXX_FLAGS})
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/rolin/workspace/github/xedit/.bin
[ 50%] Linking CXX executable xedit
ld: library not found for -licuuc
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [xedit/xedit] Error 1
make[1]: *** [xedit/CMakeFiles/xedit.dir/all] Error 2
make: *** [all] Error 2
[ 50%] Linking CXX executable xeditd
ld: library not found for -licuuc
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [xeditd/xeditd] Error 1
make[1]: *** [xeditd/CMakeFiles/xeditd.dir/all] Error 2
make: *** [all] Error 2

我不知道为什么libicuuc.dylib没有找到。

4

1 回答 1

0

link_directories只影响它之后的目标。所以我add_executablelink_directories打电话后搬家。

于 2019-06-11T09:08:08.103 回答