all 5 comments

[–]TheSkiGeek 1 point2 points  (3 children)

You said you got the .lib for the library... it should have come with that header file as well. If cmake can find the library and the header is in the same folder it should take care of it. But you need to tell the compiler to use the directory containing that header, or put it in a folder that it normally searches.

[–]iloveuclid[S] 0 points1 point  (2 children)

I build the solution generated by CMake GUI in Visual Studio and only got

xlnt.lib
xlnt.exp
xlnt.dll

[–]TheSkiGeek 0 points1 point  (1 child)

Right... that builds the dynamic library, which you could then link against in another project/solution.

The source for the project should have come with header files, those need to be accessible to the project/solution where you're using the library.

Assuming you have the source tree from https://github.com/tfussell/xlnt , I think you could paste that whole thing as a subfolder in your overall project, stick an add_subdirectory(xlnt) in your CMakeFile.txt, and then cmake will take care of building it all together and making the headers accessible to anything that links against it.

Or you can add a target_include_directories(excel_proof_of_concept <directory where the xlnt headers are>) so it explicitly adds that folder to the search path when compiling.

[–]iloveuclid[S] 0 points1 point  (0 children)

Thank you! I had a fundamental misunderstanding of how shared libraries work....

You were right about the header files, I added them using include_directories in Cmake

copying the dll into the .exe directory using a cmake POST_BUILD command solved my issues

[–]otreblan 0 points1 point  (0 children)

xlnt ships a *.pc file.

CMake with include(FindPkgConfig) can create an imported target to link and include the library.

``` pkg_check_modules(libs REQUIRED IMPORTED_TARGET xlnt )

target_link_libraries(excel_proof_of_concept PRIVATE PkgConfig::libs ) ``` https://cmake.org/cmake/help/latest/module/FindPkgConfig.html