pheamit
pheamit

Reputation: 37

Why can't I link "xlnt" library?

I've scoured SO and found some similar questions, but nothing in the answers helped me.
I'm in no way a seasoned c++ programmer, and it feels like I'm hitting a brick wall with this library.
Though I don't want to give it up, I want to learn how to do it.
Am I missing something basic?

My steps for building xlnt library:

  1. cmake .. the source of xlnt
  2. build it with MSVS 2019 as a Release x64

Sample test code:

#include "xlnt/xlnt.hpp"

int main()
{
    xlnt::workbook wb;
    xlnt::worksheet ws = wb.active_sheet();
    ws.cell("A1").value(5);
    ws.cell("B2").value("string data");
    ws.cell("C3").formula("=RAND()");
    wb.save("example.xlsx");
    return 0;
}

Project properties with .hpp and .lib directories: enter image description here

Project properties with dependencies:
(I've also copied the xlnt.dll to the root of my project) enter image description here

Errors I get when I try to run the code:

1>------ Build started: Project: xlnt-test, Configuration: Release x64 ------
1>xlnt.exp : error LNK2001: unresolved external symbol "const xlnt::exception::`vftable'" (??_7exception@xlnt@@6B@)
1>xlnt.exp : error LNK2001: unresolved external symbol "const xlnt::illegal_character::`vftable'" (??_7illegal_character@xlnt@@6B@)
1>xlnt.exp : error LNK2001: unresolved external symbol "const xlnt::invalid_attribute::`vftable'" (??_7invalid_attribute@xlnt@@6B@)
1>xlnt.exp : error LNK2001: unresolved external symbol "const xlnt::invalid_cell_reference::`vftable'" (??_7invalid_cell_reference@xlnt@@6B@)
1>xlnt.exp : error LNK2001: unresolved external symbol "const xlnt::invalid_column_index::`vftable'" (??_7invalid_column_index@xlnt@@6B@)
1>xlnt.exp : error LNK2001: unresolved external symbol "const xlnt::invalid_data_type::`vftable'" (??_7invalid_data_type@xlnt@@6B@)
1>xlnt.exp : error LNK2001: unresolved external symbol "const xlnt::invalid_file::`vftable'" (??_7invalid_file@xlnt@@6B@)
1>xlnt.exp : error LNK2001: unresolved external symbol "const xlnt::invalid_parameter::`vftable'" (??_7invalid_parameter@xlnt@@6B@)
1>xlnt.exp : error LNK2001: unresolved external symbol "const xlnt::invalid_sheet_title::`vftable'" (??_7invalid_sheet_title@xlnt@@6B@)
1>xlnt.exp : error LNK2001: unresolved external symbol "const xlnt::detail::izstream::`vftable'" (??_7izstream@detail@xlnt@@6B@)
1>xlnt.exp : error LNK2001: unresolved external symbol "const xlnt::key_not_found::`vftable'" (??_7key_not_found@xlnt@@6B@)
1>xlnt.exp : error LNK2001: unresolved external symbol "const xlnt::missing_number_format::`vftable'" (??_7missing_number_format@xlnt@@6B@)
1>xlnt.exp : error LNK2001: unresolved external symbol "const xlnt::no_visible_worksheets::`vftable'" (??_7no_visible_worksheets@xlnt@@6B@)
1>xlnt.exp : error LNK2001: unresolved external symbol "const xlnt::detail::ozstream::`vftable'" (??_7ozstream@detail@xlnt@@6B@)
1>xlnt.exp : error LNK2001: unresolved external symbol "const xlnt::unhandled_switch_case::`vftable'" (??_7unhandled_switch_case@xlnt@@6B@)
1>xlnt.exp : error LNK2001: unresolved external symbol "const xlnt::unsupported::`vftable'" (??_7unsupported@xlnt@@6B@)
1>xlnt.exp : error LNK2001: unresolved external symbol "const xlnt::detail::vector_istreambuf::`vftable'" (??_7vector_istreambuf@detail@xlnt@@6B@)
1>xlnt.exp : error LNK2001: unresolved external symbol "const xlnt::detail::vector_ostreambuf::`vftable'" (??_7vector_ostreambuf@detail@xlnt@@6B@)
1>D:\Docs\Programming\cpp\xlnt-test\x64\Release\xlnt-test.exe : fatal error LNK1120: 18 unresolved externals
1>Done building project "xlnt-test.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Upvotes: 0

Views: 1032

Answers (1)

Landstalker
Landstalker

Reputation: 1368

I tested the library for you. It work after dowing this:

  1. Downloading source from official website here
  2. Create new VS project with CMake
  3. Create a new exec project (MyTestApplication)
  4. Set additional include directories (in my case G:\CMake\Sources\xlnt-master\include)
  5. In debug mode, the genereated library is called xlntd.lib (with d suffix)

    • Add ..\source\$(Configuration)\xlntd.lib at Linker -> Input
    • $(Configuration) = Debug in debug mode
    • You can also define ..\source\$(Configuration)\ as additional library directories and put just xlntd.lib as input lib
  6. In Release mode, the genereated library is called xlnt.lib

    • Add ..\source\$(Configuration)\xlnt.lib at Linker -> Input
    • $(Configuration) = Release in release mode
    • You can also define ..\source\$(Configuration)\ as additional library directories and put just xlnt.lib as input lib

enter image description here

After dowing this, it should be OK:

enter image description here

Upvotes: 1

Related Questions