[英]On Linux, in a C++ program, how do I find the path to the shared library that was loaded?
[英]How do I use a shared library (in this case JsonCpp) in my C++ program on Linux?
我是一名新興的C ++程序員,我正在使用C ++自己編寫第一個程序。 我決定要使用JSON來存儲要使用的某些數據,並且找到了一個用於處理JSON的庫JsonCpp 。
我已經使用Linux系統的軟件包管理器安裝了該庫,並且在C ++代碼中已在源代碼文件中使用過
#include <json>
並使用g ++對其進行了編譯,它具有-ljson和-L / usr / lib選項(libjson.so位於/usr/lib
)。
但是,該庫提供的對象Json :: Value的首次使用給出了“ Json尚未聲明”的編譯錯誤。 我確定我的錯誤很簡單,所以有人可以解釋我在做什么嗎? 我沒有提到過如何使用共享庫的書,因此我不得不在Google上找到很多東西。
編輯:帶有+ -E選項的g ++給出此錯誤:
json:沒有這樣的文件或目錄。
我檢查了JsonCPP的文件列表:
include/json/autolink.h [code]
include/json/config.h [code]
include/json/features.h [code]
include/json/forwards.h [code]
include/json/json.h [code]
include/json/reader.h [code]
include/json/value.h [code]
include/json/writer.h [code]
如果標頭安裝在/usr/include
請嘗試#include <json/json.h>
。 如果它們安裝在其他地方,請使用-I
提及此路徑
g++ -I/my/lib/include -L/my/lib/lib -lmylib mysource.cpp
您是否還告訴g ++通過-I
在哪里找到頭文件-這是我對問題的猜測。
該錯誤幾乎可以肯定意味着您在實際的源文件中沒有包含#include
的錯誤。
采用
g++ -E [whatever other options]
查看cpp輸出將是檢查並查看您實際包含的內容的一種方法。
如果您實際粘貼錯誤消息,則可能會有所幫助; 您的評論暗示#include出現錯誤,但您的問題暗示其他錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.