cmake引用jansson库

妙音 posted @ 2024年1月09日 14:50 in cxx with tags json jansson c , 493 阅读

描述

 
在ubuntun系统上使用clion开发c程序, cmake如何引入jansson库.
 

下载jansson

 
wget http://digip.org/jansson/releases/jansson-2.13.tar.gz

tar -xvf
 

编译jansson

cd jansson-2.13
mkidr build
cd build
cmake ../
make
 

查看编译结果

 
├── include
│      ├── jansson_config.h
│      └── jansson.h
├── lib
│     └── libjansson.a
 
 

clion创建C程序

File->New->Project->选中"C Executable"
 

CMakeLists.txt引用jansson

 
cmake_minimum_required(VERSION 3.22)
project(demo_task C)

set(CMAKE_C_STANDARD 11)

#自定义库, jansson放在了source目录下
set(LIBHOME "/home/xxx/workspace/source/")

# jansson
include_directories(${LIBHOME}/jansson-2.13/build/include)
link_directories(${LIBHOME}/jansson-2.13/build/lib)
link_libraries(jansson)

add_executable(demo_task main.c)
 

main.c使用jansson

 
创建demo.json并放入任意json数据, jansson读取demo.json,并打印结果
 
#include <stdio.h>
#include <jansson.h>

int main() {
    json_t *json;
    json_error_t error;

    json = json_load_file("../demo.json", 0, &error);
    if(!json) {
        /* the error variable contains error information */
    }
    char *result = json_dumps(json, 0);
    printf("%s\n", result);
    free(result);

    return 0;
}
 
 

运行

 
clion运行并查看结果
 
 
 
 
 
Avatar_small
pavzi.com 说:
2024年1月10日 13:29

Pavzi.com provides all the news about Gadgets, the Economy, Technology, Business, Finance and many more. The main concept or our aim behind this website has been the will to provide resources with full information on each topic which can be accessed through the Internet. To ensure that every reader gets what is important and worthy about the topic they search and link to hear from us. pavzi.com Our site is a multiple Niche or category website which will ensure to provide information and resources on each and every topic. Some of the evergreen topics you will see on our website are Career, Job Recruitment, Educational, Technology, Reviews and others. We are targeting mostly so it is true that Tech, Finance, and Product Reviews. The only reason we have started this website is to make this site the need for your daily search use.

Avatar_small
Cheap Assignment Wri 说:
2024年1月10日 14:33

Thank you for providing the references on incorporating the Jansson library into CMake projects. Your guidance on using CLion for C development on Ubuntu has been incredibly helpful. I've successfully integrated the Jansson library into my project, and it's working seamlessly.

Avatar_small
sophia 说:
2024年1月23日 23:03

Metaverse games have long exceeded the stage of being a trend, with several games now having market capitalizations above $1 Billion..   casino online

Avatar_small
robinjack 说:
2024年1月25日 20:19

The GDP (Gross Domestic Product) of the 41 Heavily Indebted Poor Countries (567 million people) is less than the wealth of the world’s 7 richest people combined.   madrasah ibtidaiyah al muhajirin

Avatar_small
meidir 说:
2024年1月27日 00:55

Amusing article. It seems that most of the ways are depending on the creative thinking aspect. “All marriages are mixed marriages.” by Chantal Saperstein.. 홈카지노검증

Avatar_small
robinjack 说:
2024年2月14日 17:23

Spiritual guidance is the ability to receive messages from a higher source that can give us insight into our lives. It can be received in a variety of ways, including meditation, prayer, and by connecting with your spirit guides. You can also receive guidance from others in your life or through ordinary coincidences, such as seeing a light around the correct answer on a multiple-choice exam.. what does it mean to dream about a female coworker

Avatar_small
sophia 说:
2024年2月14日 22:04

I havent any word to appreciate this post.....Really i am impressed from this post....the person who create this post it was a great human..thanks for shared this with us. bestoto

Avatar_small
sophia 说:
2024年2月16日 01:51

MusicVerter is a free SoundCloud to MP3 downloader. Download any SoundCloud song or playlist directly into an MP3 file for free with just one click. Try it now! SoundCloud Downloader - SoundCloud To MP3 Converter. soundcloud downloader

Avatar_small
Masaood TBA 说:
2024年2月24日 19:56

Al Masaood Tyres is a premier destination for all your tire needs in Abu Dhabi, known for its exceptional service and extensive range of top-tier tire brands. With a team of skilled professionals, they provide expert advice and efficient solutions to ensure your vehicle's optimal performance and safety on the road.

Avatar_small
10 deep hoodie 说:
2024年3月06日 03:53

The 10 Deep hoodie is an absolute must-have! The quality and comfort of this hoodie are unmatched, making it perfect for any casual or streetwear look. 10 deep hoodie

Avatar_small
sophia 说:
2024年3月13日 01:19 I havent any word to appreciate this post.....Really i am impressed from this post....the person who create this post it was a great human..thanks for shared this with us. gmail.com login
Avatar_small
Thai Townhouse Prope 说:
2024年3月19日 14:03

Thai-Move is a web based search platform which allows people from anywhere in the world to search for any type of property in Thailand. Agents from all over Thailand can list all of their properties easily and in one place giving the people searching the ability to not only search for everything without switching websites, but be able to save and compare one property to the next.

Avatar_small
נייק טי אן 说:
2024年3月19日 16:52

מחפשים נעלי נייק ? אצלנו במול שוז אתם במקום הנכון לנעלי נייק גברים, נייק נשים או ילדים! באתר תמצאו מגוון דגמי נעלי ספורט נייק לפעילויות שונות כגון כדורגל, כדורסל, , טניס ועוד. זקוקים לייעוץ בנוגע לבחירת נעלי נייק? צרו עימנו קשר !

Avatar_small
Redhead Pick Up Line 说:
2024年3月19日 19:36

Imagine approaching a flame-haired beauty with a playful grin and saying, "Is it just me, or is it getting hotter in here? Oh wait, it's just your fiery locks stealing all the attention." This line not only acknowledges the unique allure of red hair but also serves as a lighthearted compliment, sure to bring a smile to their face and spark a conversation.

Avatar_small
educational apps 说:
2024年3月29日 09:33

Educational apps are invaluable tools for modern learners of all ages. With their interactive features and diverse content, these apps make learning accessible anytime, anywhere. <a href="https://takesapp.com/top-10-educational-apps-for-kids/">educational apps</a>


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter