0

I work on macbook with newest OS. Installed icu4c library via homebrew. But I cannot link libicuuc correctly. In case of find library, I use

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

on my ~/.bashrc, but still got link error.

This is a very simple 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})

It generate:

/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

I don't known why libicuuc.dylib not found.

Michael Foukarakis
  • 39,737
  • 6
  • 87
  • 123
linrongbin
  • 2,967
  • 6
  • 31
  • 59
  • source code repository: https://github.com/xedit/xedit – linrongbin Jun 11 '19 at 08:53
  • 1
    You incorrectly order `link_directories` after `add_executable`. [That answer](https://stackoverflow.com/a/40554704/3440745) to the duplicate question describes such error. – Tsyvarev Jun 11 '19 at 09:12

1 Answers1

0

link_directories only affects targets that come AFTER it. So I move add_executable after the link_directories call.

linrongbin
  • 2,967
  • 6
  • 31
  • 59