How to link additional libraries #71
-
I have initialized a C project "foobar" and made the following changes:
Obviously, my attempt is to link
fails:
Could you help me to fix this problem? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
On GNU systems the same can be done with I recommend not relying to non-standard extensions if not necessary. Regarding if(CMAKE_SYSTEM_NAME MATCHES Linux) # probably right?
include(CheckLibraryExists)
check_library_exists(m pow "" LIBM_FOUND)
if(LIBM_FOUND)
target_link_libraries(project_target PRIVATE m)
endif()
endif() would be the way to handle it, but I'm not sure. |
Beta Was this translation helpful? Give feedback.
M_PI
is a non-standard feature of some C standard libraries. On Windows for example,_USE_MATH_DEFINES
is how you enable this extension: https://docs.microsoft.com/en-us/cpp/c-runtime-library/math-constants?view=msvc-170On GNU systems the same can be done with
_XOPEN_SOURCE
: https://man7.org/linux/man-pages/man7/feature_test_macros.7.html#:~:text=the%20man%20pages.-,_XOPEN_SOURCE,-Defining%20this%20macroI recommend not relying to non-standard extensions if not necessary.
Regarding
libm
, it's a Linux-only thing and I'm not totally certain how it could be best handled. Maybe something along the lines of: