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

Undefined reference when trying to make #114

Open
sinashan opened this issue Jan 21, 2022 · 1 comment
Open

Undefined reference when trying to make #114

sinashan opened this issue Jan 21, 2022 · 1 comment

Comments

@sinashan
Copy link

Hi

I'm using cmake for syscall_intercept. Now, when I want to make, I get the following error:

[  0%] Built target gen_ctags
[  0%] Built target check_whitespace
[  2%] Built target cpp_test
[  2%] Built target cstyle
Scanning dependencies of target syscall_intercept_base_c
[  3%] Building C object CMakeFiles/syscall_intercept_base_c.dir/src/disasm_wrapper.c.o
[  4%] Building C object CMakeFiles/syscall_intercept_base_c.dir/src/intercept.c.o
[  4%] Building C object CMakeFiles/syscall_intercept_base_c.dir/src/intercept_desc.c.o
[  5%] Building C object CMakeFiles/syscall_intercept_base_c.dir/src/intercept_log.c.o
[  6%] Building C object CMakeFiles/syscall_intercept_base_c.dir/src/intercept_util.c.o
[  6%] Building C object CMakeFiles/syscall_intercept_base_c.dir/src/patcher.c.o
[  7%] Building C object CMakeFiles/syscall_intercept_base_c.dir/src/magic_syscalls.c.o
[  8%] Building C object CMakeFiles/syscall_intercept_base_c.dir/src/syscall_formats.c.o
[  8%] Built target syscall_intercept_base_c
Scanning dependencies of target syscall_intercept_base_clf
[  8%] Building C object CMakeFiles/syscall_intercept_base_clf.dir/src/cmdline_filter.c.o
[  8%] Built target syscall_intercept_base_clf
Scanning dependencies of target syscall_intercept_base_asm
[  8%] Building ASM object CMakeFiles/syscall_intercept_base_asm.dir/src/intercept_template.S.o
[  9%] Building ASM object CMakeFiles/syscall_intercept_base_asm.dir/src/util.S.o
[  9%] Building ASM object CMakeFiles/syscall_intercept_base_asm.dir/src/intercept_wrapper.S.o
[  9%] Built target syscall_intercept_base_asm
Scanning dependencies of target syscall_intercept_unscoped
[ 10%] Linking C static library libsyscall_intercept_unscoped.a
[ 10%] Built target syscall_intercept_unscoped
Scanning dependencies of target generate_syscall_intercept_scoped
[ 11%] Generating syscall_intercept_unscoped.o
[ 12%] Generating syscall_intercept_scoped.o
[ 12%] Built target generate_syscall_intercept_scoped
Scanning dependencies of target syscall_intercept_shared
[ 12%] Linking C shared library libsyscall_intercept.so
[ 14%] Built target syscall_intercept_shared
Scanning dependencies of target syscall_intercept_static
[ 15%] Linking C static library libsyscall_intercept.a
[ 16%] Built target syscall_intercept_static
Scanning dependencies of target check_license_executable
[ 16%] Building C object CMakeFiles/check_license_executable.dir/utils/check_license/check-license.c.o
[ 17%] Linking C executable check_license_executable
[ 17%] Built target check_license_executable
Scanning dependencies of target syscall_logger
[ 17%] Building C object examples/CMakeFiles/syscall_logger.dir/syscall_logger.c.o
[ 18%] Building C object examples/CMakeFiles/syscall_logger.dir/syscall_desc.c.o
[ 19%] Linking C shared library libsyscall_logger.so
[ 19%] Built target syscall_logger
Scanning dependencies of target fork_ban
[ 19%] Building C object examples/CMakeFiles/fork_ban.dir/fork_ban.c.o
[ 20%] Linking C shared library libfork_ban.so
[ 20%] Built target fork_ban
Scanning dependencies of target icap
[ 21%] Building C object examples/CMakeFiles/icap.dir/icap.c.o
[ 21%] Linking C shared library libicap.so
[ 21%] Built target icap
Scanning dependencies of target vfork_logging
[ 22%] Building C object test/CMakeFiles/vfork_logging.dir/vfork_logging.c.o
[ 23%] Linking C executable vfork_logging
[ 23%] Built target vfork_logging
Scanning dependencies of target intercept_sys_write
[ 24%] Building C object test/CMakeFiles/intercept_sys_write.dir/intercept_sys_write.c.o
[ 25%] Linking C shared library libintercept_sys_write.so
[ 25%] Built target intercept_sys_write
Scanning dependencies of target test_clone_thread_preload
[ 26%] Building C object test/CMakeFiles/test_clone_thread_preload.dir/test_clone_thread_preload.c.o
[ 26%] Linking C shared library libtest_clone_thread_preload.so
[ 26%] Built target test_clone_thread_preload
Scanning dependencies of target test_clone_thread
[ 26%] Building C object test/CMakeFiles/test_clone_thread.dir/test_clone_thread.c.o
[ 27%] Linking C executable test_clone_thread
[ 27%] Built target test_clone_thread
Scanning dependencies of target filter_test
[ 27%] Building C object test/CMakeFiles/filter_test.dir/filter_test.c.o
[ 28%] Linking C executable filter_test
../libsyscall_intercept.so.0.1.0: undefined reference to `cs_option'
../libsyscall_intercept.so.0.1.0: undefined reference to `cs_free'
../libsyscall_intercept.so.0.1.0: undefined reference to `cs_disasm_iter'
../libsyscall_intercept.so.0.1.0: undefined reference to `cs_malloc'
../libsyscall_intercept.so.0.1.0: undefined reference to `cs_open'
../libsyscall_intercept.so.0.1.0: undefined reference to `cs_close'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [test/filter_test] Error 1
make[1]: *** [test/CMakeFiles/filter_test.dir/all] Error 2
make: *** [all] Error 2

What does this "undefined reference" mean? And how can I solve the issue? Thanks

@gohar94
Copy link

gohar94 commented Apr 8, 2022

I was running into a similar issue with an undefined reference to cs_open (although at runtime).

I am building my project using CMake and was able to resolve it by linking to the capstone library explicitly by adding the following source:

include(FindPkgConfig)

pkg_check_modules (CAPSTONE REQUIRED capstone)

# Use CAPSTONE_FOUND, CAPSTONE_LIBRARIES, CAPSTONE_INCLUDE_DIRS vars
target_link_libraries(${PROJECT_NAME} ${CAPSTONE_LIBRARIES})

If you are not using CMake, you might have to do something equivalent by explicitly linking against the capstone library. This could be something like adding -llibcapstone to your build command.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants