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

Building example throws undefined references #156

Open
Himeshi opened this issue May 18, 2018 · 8 comments
Open

Building example throws undefined references #156

Himeshi opened this issue May 18, 2018 · 8 comments

Comments

@Himeshi
Copy link

Himeshi commented May 18, 2018

Tried to build the example on Ubuntu 14.04 in check-0.12.0 with check installed from source using cmake (because the ap-get sources aren't up to date and was missing some basic functions such as ck_assert_float_eq). It fails with following errors.

[ 16%] Building C object src/CMakeFiles/money.dir/money.c.o
[ 33%] Linking C static library libmoney.a
[ 33%] Built target money
Scanning dependencies of target main
[ 50%] Building C object src/CMakeFiles/main.dir/main.c.o
[ 66%] Linking C executable main
[ 66%] Built target main
Scanning dependencies of target check_money
[ 83%] Building C object tests/CMakeFiles/check_money.dir/check_money.c.o
[100%] Linking C executable check_money
/usr/local/lib/libcheck.a(check.c.o): In function `tcase_create':
check-0.11.0/src/check.c:145: undefined reference to `floor'
check-0.11.0/src/check.c:148: undefined reference to `floor'
/usr/local/lib/libcheck.a(check.c.o): In function `tcase_set_timeout':
check-0.11.0/src/check.c:332: undefined reference to `floor'
check-0.11.0/src/check.c:334: undefined reference to `floor'
/usr/local/lib/libcheck.a(check.c.o): In function `check_get_clockid':
check-0.11.0/src/check.c:616: undefined reference to `timer_create'
check-0.11.0/src/check.c:618: undefined reference to `timer_delete'
/usr/local/lib/libcheck.a(check_run.c.o): In function `tcase_run_tfun_fork':
check-0.11.0/src/check_run.c:507: undefined reference to `timer_create'
check-0.11.0/src/check_run.c:515: undefined reference to `timer_settime'
check-0.11.0/src/check_run.c:529: undefined reference to `timer_delete'
collect2: error: ld returned 1 exit status
tests/CMakeFiles/check_money.dir/build.make:96: recipe for target 'tests/check_money' failed
make[2]: *** [tests/check_money] Error 1
CMakeFiles/Makefile2:179: recipe for target 'tests/CMakeFiles/check_money.dir/all' failed
make[1]: *** [tests/CMakeFiles/check_money.dir/all] Error 2
Makefile:138: recipe for target 'all' failed
make: *** [all] Error 2
@brarcher
Copy link
Contributor

This appears to be an issue with linking statically but the static flags from libcheck are not being included. I wonder if this is an issue with the pkg-config file installed by Ubuntu is being used and not the file which you installed along with Check when you compiled from source. The example builds and tests successfully on Linux and macOS for me, so my hunch is it is something about the old Check trying to be used instead of the Check you built.

Here is another issue logged about Check and Ubuntu, in case it is helpful.

@Misairu-G
Copy link

Misairu-G commented Jun 29, 2018

Ubuntu 16.04, I resolved this by changing STATIC to SHARED of the add_library command in lib/CMakeLists.txt and src/CMakeLists.txt before compile check

@brarcher
Copy link
Contributor

brarcher commented Jul 3, 2018

Unfortunately, changing from STATIC to SHARED breaks the Windows builds, and CMake is primarily used to support Windows. Is the same issue found when using the configure script? The configure script is the official support path for *nix.

@Himeshi
Copy link
Author

Himeshi commented Nov 20, 2018

Using the configure script instead of cmake when building resolved this issue.

@elken
Copy link

elken commented Feb 26, 2019

If it's a consideration to push forward with only CMake, adding a platform check such as if(WIN32) could be used to distinguish between platforms. Can confirm it works with projects I've worked on, couldn't vouch on its success here but I could sure test it.

@dernasherbrezon
Copy link

Had the same error. Fixed by installing "pkg-config":

sudo apt-get install pkg-config

@mikkoi
Copy link
Contributor

mikkoi commented Dec 20, 2019

The version 0.13.0 CMake build should fix this.

@jgcrunden
Copy link

jgcrunden commented Jun 25, 2021

I had the same error too, building in a Debian based docker container.
I added the following condition into my CMakeList.txt file to check for a Debian based distro and to dynamically link the math, rt, pthread and subunit libraries if true. My programme now compiles in the docker container (Debian), and both on my Arch Linux dev environment and Windows (cygwin) dev environment where else() part of the condition is met.

find_program(DEBIAN "dpkg")
if(DEBIAN)
    target_link_libraries(${PROJECT_NAME} check m rt pthread subunit)
else()
    target_link_libraries(${PROJECT_NAME} check)
endif()

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

7 participants