Error loading shared libraries: libcmocka.so.0: No such file or directory

#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
/* A test case that does nothing and succeeds. */
static void null_test_success(void **state) {
    (void) state; /* unused */
}
int main(void) {
    const UnitTest tests[] = {
        unit_test(null_test_success),
    };
    return run_tests(tests);
}

I am new to cmocka unit testing platform, http://www.ohloh.net/p/cmocka . When I compiled the above program as gcc program.c -lcmocka and when I started. /a.out, I got an error:

./a.out: error while loading shared libraries: libcmocka.so.0: cannot open shared objects file: no such file or directory

I tried, but can't fix it. What exactly is the problem here?

+5
source share
3 answers

, cmocka. , (, libmocka.so.x), "/etc/ld.so.conf". LD_LIBRARY_PATH .

( ) "" , /usr/lib /usr/local/lib, .

0

, /usr/local/lib/

ls -lart/usr/local/lib/libcmocka.so ,

+1

cmake , cmake:

# Find and add the cmocka library
find_library(CMOCKA_LIBRARY NAMES cmocka)
add_library(cmocka SHARED IMPORTED)
set_property(TARGET cmocka PROPERTY IMPORTED_LOCATION "${CMOCKA_LIBRARY}")

# Create and link the testing file to cmocka
add_executable(mytest my_example_test.c)
target_link_libraries(mytest cmocka)

# Add this as a test for ctest
add_test(TEST_MY_EXAMPLE mytest)

:

gcc my_example_test.c -L/usr/local/lib -lcmocka -o mytest && ./mytest

In the latter case, you can use the option -Lto tell gcc where to look for library files. In this case, if you installed it somewhere unconventional, gcc can still find it if you specify where the library files are.

0
source

All Articles