0

How do I connect the libxlsxwriter library to my personal project using CMake.

I cloned the official library files from https://github.com/jmcnamara/libxlsxwriter.

Then I extracted it in my personal project and added a few lines of CMake:


cmake_minimum_required(VERSION 3.11.0)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

[enter image description here][1]

include(FetchContent)
FetchContent_Declare(
  googletest
  GIT_REPOSITORY https://github.com/google/googletest.git
  GIT_TAG        main # release-1.10.0
)

include(FetchContent)
FetchContent_Declare(
        Bcrypt
        GIT_REPOSITORY https://github.com/veltro123/Bcrypt.cpp
        GIT_TAG master
)
FetchContent_MakeAvailable(Bcrypt)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)

# Now simply link against gtest or gtest_main as needed. Eg

#ADDED
include_directories("libxlsxwriter/include")
set(XLSXWRITER_LIBRARY "libxlsxwriter/build/libxlsxwriter.a")
add_library(xlsxwriter STATIC IMPORTED)
set_target_properties(xlsxwriter PROPERTIES IMPORTED_LOCATION ${XLSXWRITER_LIBRARY})
target_link_libraries(${PROJECT_NAME} xlsxwriter)
#END

project(MONEYTRACKER)
enable_testing()

add_executable(${PROJECT_NAME} main.cpp Src/Transaction.cpp Src/Date.cpp Src/User.cpp)
add_executable(${PROJECT_NAME}-ut Testing/DateTests.cpp Testing/UserTests.cpp Src/Transaction.cpp Src/Date.cpp Src/User.cpp)

target_link_libraries(${PROJECT_NAME}-ut gtest_main)
target_link_libraries(${PROJECT_NAME} PRIVATE bcrypt)

include(GoogleTest)
gtest_discover_tests(${PROJECT_NAME}-ut)

This is the error I get:

enter image description here

jmcnamara
  • 38,196
  • 6
  • 90
  • 108
veltronic
  • 9
  • 2
  • For what it is worth here are the libxlsxwriter build instructions: https://libxlsxwriter.github.io/getting_started.html – jmcnamara Feb 05 '23 at 02:00
  • What do you mean by the line "cloned library files"? You didn't build them yourself? Or you cloned the sources and built? Why do you post an image of the errors and not copy paste the text? – Milan Š. Feb 05 '23 at 08:37
  • 1
    Does this answer your question? [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – fabian Feb 05 '23 at 11:33

0 Answers0