I'm currently developing a binding of a C++
library to NodeJS
. While my binding builds and works properly in Linux
, I'm having problem with building it in Windows
, specifically in linking process. This is the error log. (I only copied a part)
...
tag.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __cdecl TagLib::String::~String(void)" (__imp_??1String@TagLib@@UEAA@XZ) referenced in function "private: class Napi::Value __cdecl Tag::GetAlbum(class Napi::CallbackInfo const &)" (?GetAlbum@Tag@@AEAA?AVValue@Napi@@AEBVCallbackInfo@3@@Z) [C:\Users\anesin1109\Downloads\taglib-node-binding-master\build\taglib-node-binding-native.vcxproj]
tag.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl TagLib::String::to8Bit(bool)const " (__imp_?to8Bit@String@TagLib@@QEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@_N@Z) referenced in function "private: class Napi::Value __cdecl Tag::GetAlbum(class Napi::CallbackInfo const &)" (?GetAlbum@Tag@@AEAA?AVValue@Napi@@AEBVCallbackInfo@3@@Z) [C:\Users\anesin1109\Downloads\taglib-node-binding-master\build\taglib-node-binding-native.vcxproj]
C:\Users\anesin1109\Downloads\taglib-node-binding-master\build\Release\taglib-node-binding-native.node : fatal error LNK1120: 24 unresolved externals [C:\Users\anesin1109\Downloads\taglib-node-binding-master\build\taglib-node-binding-native.vcxproj]
I tried to fix this in various ways-changing the C++ library build options, using different MSVS
versions, using cmake-js
instead of node-gyp
(by the way, I am liking it so I will not move back), and more. Because I can't even figure out what's the problem, I can't guess which information would be helpful to fix this issue. So I just putted the repository link and I will update the question if someone requests any kind of information. Here's the environment information of the last build:
Node v10.16.3, cmake-js v5.3.2, cmake 3.15.3, Visual Studio 2019 x64
+And this is the CMakeLists.txt:
project(taglib-node-binding-native)
set(TAGLIB_VERSION "v1.11.1")
include(ExternalProject)
set(CMAKE_VERBOSE_MAKEFILE OFF)
set(SUPPORT_LARGE_FILES ON)
if(UNIX AND NOT APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -std=c++11")
elseif(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W0 /D_WIN32_WINNT=0x0601")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -stdlib=libc++ -mmacosx-version-min=10.10")
endif()
ExternalProject_Add(
taglib
PREFIX "${CMAKE_SOURCE_DIR}/taglib"
GIT_REPOSITORY https://github.com/taglib/taglib
GIT_TAG ${TAGLIB_VERSION}
INSTALL_DIR "${CMAKE_SOURCE_DIR}/taglib"
CMAKE_ARGS "-DCMAKE_INSTALL_PREFIX=${CMAKE_SOURCE_DIR}/taglib"
CMAKE_CACHE_ARGS "-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=true"
)
ExternalProject_Add_Step(
taglib
forcebuild
COMMAND ${CMAKE_COMMAND} -E echo_append ""
DEPENDEES configure
DEPENDEES build
ALWAYS 1
)
link_directories(${CMAKE_SOURCE_DIR}/taglib/lib)
include_directories(BEFORE ${CMAKE_JS_INC} ${CMAKE_SOURCE_DIR}/taglib/include ${CMAKE_SOURCE_DIR}/node_modules/node-addon-api)
file(GLOB SOURCE_FILES "src/*.cc" "src/*.h")
add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES})
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "" SUFFIX ".node")
add_dependencies(${PROJECT_NAME} taglib)
target_link_libraries(${PROJECT_NAME} ${CMAKE_JS_LIB} tag)
Edit: Someone marked this question as a duplicate, but I don't think the linked question gives me an answer for this.