Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when compiling #24

Open
ghost opened this issue Nov 21, 2022 · 4 comments
Open

Error when compiling #24

ghost opened this issue Nov 21, 2022 · 4 comments
Labels
question Further information is requested

Comments

@ghost
Copy link

ghost commented Nov 21, 2022

Debian 11

Hi,

I have problem with downloaded binary even with compiling source code.

Try to run compiled

root@xxx:/home/xxxxx# ./check_rest_api-1.2.0 
./check_rest_api-1.2.0: error while loading shared libraries: libjson-c.so.2: cannot open shared object file: No such file or directory
ii  libfastjson4:amd64                   0.99.9-1                       amd64        fast json library for C
ii  libjson-c-dev                        0.15-2                         amd64        JSON manipulation library - development files
ii  libjson-c5:amd64                     0.15-2                         amd64        JSON manipulation library - shared library
ii  libjsoncpp-dev:amd64                 1.9.4-4                        amd64        library for reading and writing JSON for C++ (devel files)
ii  libjsoncpp24:amd64                   1.9.4-4                        amd64        library for reading and writing JSON for C++
rc  python-jsonschema                    2.6.0-4                        all          An(other) implementation of JSON Schema (Draft 3 and 4) - Python 2.7

Compiling error

root@xxx:/home/xxxx/check_rest_api/src# make
gcc -c -o check_rest_api.o check_rest_api.c -Wall -Werror
check_rest_api.c:5:10: fatal error: json/json_tokener.h: No such file or directory
    5 | #include <json/json_tokener.h>
      |          ^~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make: *** [Makefile:8: check_rest_api.o] Error 1

Thank for help

@xWyatt
Copy link
Owner

xWyatt commented Nov 21, 2022

If you have pkg-config installed can you give me the output of:

  • pkg-config --cflags --libs json-c

I don't have a Debian machine handy to test on at the moment.

@xWyatt xWyatt added the question Further information is requested label Nov 21, 2022
@neubi4
Copy link

neubi4 commented Dec 19, 2022

Hi,

output of pkg-config --cflags --libs json-c:

# pkg-config --cflags --libs json-c
-I/usr/include/json-c -ljson-c

Issue seems that in Debian, the header files of json-c are in /usr/include/json-c . I tried to update the code like this:

diff --git a/src/check_rest_api.c b/src/check_rest_api.c
index 9c907d2..d19a363 100644
--- a/src/check_rest_api.c
+++ b/src/check_rest_api.c
@@ -2,9 +2,9 @@
 #include <stdlib.h>
 #include <string.h>
 #include <curl/curl.h>
-#include <json/json_tokener.h>
-#include <json/json_object.h>
-#include <json/json_util.h>
+#include <json-c/json_tokener.h>
+#include <json-c/json_object.h>
+#include <json-c/json_util.h>

 #include "headers/check_rest_api.h"
 #include "headers/read_input.h"
diff --git a/src/check_thresholds.c b/src/check_thresholds.c
index a23b6a8..59d28ca 100644
--- a/src/check_thresholds.c
+++ b/src/check_thresholds.c
@@ -4,9 +4,9 @@
 #include <ctype.h>

 #include <curl/curl.h>
-#include <json/json_tokener.h>
-#include <json/json_object.h>
-#include <json/json_util.h>
+#include <json-c/json_tokener.h>
+#include <json-c/json_object.h>
+#include <json-c/json_util.h>

 #include "headers/check_rest_api.h"
 #include "headers/read_input.h"

But when compiling it i get another error:

# make
gcc -c -o check_rest_api.o check_rest_api.c -Wall -Werror
gcc -c -o read_input.o read_input.c -Wall -Werror
gcc -o check_rest_api check_rest_api.o read_input.o check_thresholds.c -Wall -Werror -lcurl -ljson-c
/usr/bin/ld: read_input.o:(.bss+0x0): multiple definition of `argVals'; check_rest_api.o:(.bss+0x0): first defined here
/usr/bin/ld: /tmp/ccLzaMMq.o:(.bss+0x0): multiple definition of `argVals'; check_rest_api.o:(.bss+0x0): first defined here
collect2: error: ld returned 1 exit status
make: *** [Makefile:11: check_rest_api] Error 1

Sine i have no c knowledge, i dotn know what the problem is :(

@sinewave-2097
Copy link

FWIW, I get the exact same compilation errors on Ubuntu 22.04.2 LTS using v1.2.0 or v1.2.1.

@maggu
Copy link

maggu commented May 7, 2024

There are two issues mentioned here. Regarding the header files in the original comment:

I checked the current status on RHEL. On RHEL 9 it's the same as on Debian and Ubuntu: The header files are placed in /usr/include/json-c and the code doesn't compile. Om RHEL 7 (soon to be EoL), they are located in /usr/include/json, but then /usr/include/json-c is created as a symlink. So I believe the includes in this repository can safely (and should) be changed from json to json-c by now.

Then there's the linking error, which is because argVals is definied in read_input.h. It should instead be declared as extern struct.

These commands make the required adjustments:

sed -i 's%^#include <json/%#include <json-c/%' *.c
sed -i 's%^struct%extern struct%' headers/read_input.h

All in all, I think this issue should be tagged as a bug, and the above changes made. (I don't believe a PR is called for here, but I can make one nonetheless if preferable.)

xWyatt added a commit that referenced this issue Jun 7, 2024
xWyatt added a commit that referenced this issue Jun 7, 2024
Fixes the other portion of #24

Thanks @maggu for triaging #24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants