Have some troubles to use lib installed with vcpkg in vscode and gcc


I'm a beginner in C and I want to use a lib called json-c. So I followed the git tutoriel and I installed vcpkg. After that I run the command:

vcpkg install json-c
vcpkg integrate install

So now vscode can see the new lib, i see function descriptions, etc..

I created a task to compile the code:

  "version": "2.0.0",
  "tasks": [
      "label": "build",
      "type": "shell",
      "command": "gcc",
      "args": [

And in the include directory there is all header files. enter image description here enter image description here

But when i run the task, i have this errors:

> Executing task: gcc -g lib.c -o lib.exe -I c:/Users/antoi/Downloads/vcpkg-master/vcpkg-master/installed/x86-windows/include/ <

c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\antoi\AppData\Local\Temp\ccVFMijo.o: in function `main':
c:\Users\antoi\Documents\GitHub\Hashcode2019/lib.c:23: undefined reference to `json_tokener_parse'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: c:\Users\antoi\Documents\GitHub\Hashcode2019/lib.c:24: undefined reference to `json_object_to_json_string_ext'
collect2.exe: error: ld returned 1 exit status
The terminal process terminated with exit code: 1

Terminal will be reused by tasks, press any key to close it.

And my code:

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <json-c/json.h>

int main(void)
    struct json_object *jobj;
    char *str = "{ \"msg-type\": [ \"0xdeadbeef\", \"irc log\" ], \
        \"msg-from\": { \"class\": \"soldier\", \"name\": \"Wixilav\" }, \
        \"msg-to\": { \"class\": \"supreme-commander\", \"name\": \"[Redacted]\" }, \
        \"msg-log\": [ \
            \"soldier: Boss there is a slight problem with the piece offering to humans\", \
            \"supreme-commander: Explain yourself soldier!\", \
            \"soldier: Well they don't seem to move anymore...\", \
            \"supreme-commander: Oh snap, I came here to see them twerk!\" \
            ] \

    printf("str:\n---\n%s\n---\n\n", str);

    jobj = json_tokener_parse(str);
    printf("jobj from str:\n---\n%s\n---\n", json_object_to_json_string_ext(jobj, JSON_C_TO_STRING_SPACED | JSON_C_TO_STRING_PRETTY));

Thank you !

asked on Stack Overflow Nov 2, 2019 by blaud antoine

0 Answers

Nobody has answered this question yet.

User contributions licensed under CC BY-SA 3.0