Using libjson in a C++ project

帅比萌擦擦* 提交于 2019-12-11 03:54:41

问题


I'm trying to use libjson within a C++ project and the docs tell me to just "add libjson's source to your project, comment JSON_LIBRARY in the JSONOptions.h file and any C++ compiler should compile it."

Being quite new to C++ and all that, how exactly am I supposed to do that (not using any IDE)? Should I just #include the libjson.h file and that's it? Shouldn't I reference libjson somehow in my call to g++ when compiling my project?

thx in advance


回答1:


You have to:

One,

#include <libjson.h>

in order to get access to the functions and data types the library offers, then

Two, link against the libjsonz library:

g++ -o myprogram myprogram.c -ljson

(the -ljson flag has to come last or you'll get a linker error with never versions of GCC.)

EDIT: if you need to build the library, you typically have a configure script or a Makefile. See how to use them.




回答2:


If you go into the libjson library folder, you will see a makefile. Navigate to that directory in a terminal and type:

make

then

make install

Then, in your code

#include <libjson.h>

or, depending on your include path:

#include <libjson/libjson.h>

That should be all that you need to do.

If you need additional help, you can post in the help forum at sourceforge (I am the author of libjson)




回答3:


if you install json you should find include file at /usr/local/include so

#include <json/json.h>

gcc exasmple.c -ljson



来源:https://stackoverflow.com/questions/11842976/using-libjson-in-a-c-project

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!