簡體   English   中英

為什么我不能鏈接“xlnt”庫?

[英]Why can't I link "xlnt" library?

我搜索了SO並發現了一些類似的問題,但答案中沒有任何幫助。
我絕不是一個經驗豐富的c++程序員,感覺就像我用這個庫撞到了磚牆。
雖然我不想放棄,但我想學習如何去做。
我錯過了一些基本的東西嗎?

我構建xlnt庫的步驟

  1. cmake .. xlnt的來源
  2. 使用 MSVS 2019 作為Release x64構建它

示例測試代碼

#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;
}

具有.hpp.lib目錄的項目屬性 在此處輸入圖片說明

具有依賴項的項目屬性
(我也將xlnt.dll復制到了我的項目的根目錄) 在此處輸入圖片說明

嘗試運行代碼時出現的錯誤:

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 ==========

我為你測試了這個庫。 這樣做后它可以工作:

  1. 從官網下載源碼在這里
  2. 使用 CMake 創建新的 VS 項目
  3. 創建一個新的 exec 項目 ( MyTestApplication )
  4. 設置額外的包含目錄(在我的例子中G:\\CMake\\Sources\\xlnt-master\\include
  5. 調試模式下,生成的庫名為xlntd.lib (后綴為d

    • Linker -> Input處添加..\\source\\$(Configuration)\\xlntd.lib
    • $(配置)= Debug的調試模式
    • 您還可以將..\\source\\$(Configuration)\\為附加庫目錄,並將xlntd.lib作為輸入庫
  6. Release模式下,生成的庫稱為xlnt.lib

    • Linker -> Input處添加..\\source\\$(Configuration)\\xlnt.lib
    • $(配置)= Release在釋放模式
    • 您還可以將..\\source\\$(Configuration)\\為附加庫目錄,並將xlnt.lib作為輸入庫

在此處輸入圖片說明

dowing在此之后,它應該是OK

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM