CMake CHECK_FUNCTION_EXISTS for a function requiring #defineWhat does “#define _GNU_SOURCE” imply?Symbol lookup in CMake fails although symbol is presentcmake and libpthreadWhat is CMake equivalent of 'configure --prefix=DIR && make all install '?Debug vs Release in CMakeDefine preprocessor macro through cmakeLooking for a 'cmake clean' command to clear up CMake outputCMake : <pthread.h> not found in WindowsCMake install is not installing libraries on Windowscmake try_compile: Using library found in configurecmake using corrext c++ standard when checking for header filesCMake can find one Boost header file but not another
Character had a different name in the past. Which name should I use in a flashback?
Novel where a cube cooled below absolute zero makes a hole in reality
Why does Taylor’s series “work”?
Are there any crystals that are theoretically possible, but haven't yet been made?
Is it a good idea to teach algorithm courses using pseudocode instead of a real programming language?
Gambler's Fallacy Dice
Bookshelves: the intruder
Is presenting a play showing Military charactes in a bad light a crime in the US?
Very serious stuff - Salesforce bug enabled "Modify All"
How was the blinking terminal cursor invented?
What's is the easiest way to purchase a stock and hold it
How to choose the correct exposure for flower photography?
Head-internal relative clauses
Have the writers and actors of Game Of Thrones responded to its poor reception?
What were the "pills" that were added to solid waste in Apollo 7?
Should I twist DC power and ground wires from a power supply?
How to determine the distribution of Ubuntu
Addressing an email
Why could the Lunar Ascent Engine be used only once?
Latin words remembered from high school 50 years ago
What does this 'x' mean on the stem of the voice's note, above the notehead?
Working hours and productivity expectations for game artists and programmers
Why is python script running in background consuming 100 % CPU?
Who is frowning in the sentence "Daisy looked at Tom frowning"?
CMake CHECK_FUNCTION_EXISTS for a function requiring #define
What does “#define _GNU_SOURCE” imply?Symbol lookup in CMake fails although symbol is presentcmake and libpthreadWhat is CMake equivalent of 'configure --prefix=DIR && make all install '?Debug vs Release in CMakeDefine preprocessor macro through cmakeLooking for a 'cmake clean' command to clear up CMake outputCMake : <pthread.h> not found in WindowsCMake install is not installing libraries on Windowscmake try_compile: Using library found in configurecmake using corrext c++ standard when checking for header filesCMake can find one Boost header file but not another
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I a CMake project, I am trying to test for availability of pthread_setname_np()
. As for the headers, this function prototype only seems to be exposed if I #define _GNU_SOURCE
first.
Probably for this reason, simply doing
CHECK_FUNCTION_EXISTS(pthread_setname_np HAVE_PTHREAD_SETNAME_NP)
will not detect the function even though it is present. The documentation mentions CMAKE_REQUIRED_DEFINITIONS
but I am not sure how to use it (nor if it is the right way at all).
How can I get CMake to correctly detect the presence of this function?
cmake pthreads
add a comment |
I a CMake project, I am trying to test for availability of pthread_setname_np()
. As for the headers, this function prototype only seems to be exposed if I #define _GNU_SOURCE
first.
Probably for this reason, simply doing
CHECK_FUNCTION_EXISTS(pthread_setname_np HAVE_PTHREAD_SETNAME_NP)
will not detect the function even though it is present. The documentation mentions CMAKE_REQUIRED_DEFINITIONS
but I am not sure how to use it (nor if it is the right way at all).
How can I get CMake to correctly detect the presence of this function?
cmake pthreads
add a comment |
I a CMake project, I am trying to test for availability of pthread_setname_np()
. As for the headers, this function prototype only seems to be exposed if I #define _GNU_SOURCE
first.
Probably for this reason, simply doing
CHECK_FUNCTION_EXISTS(pthread_setname_np HAVE_PTHREAD_SETNAME_NP)
will not detect the function even though it is present. The documentation mentions CMAKE_REQUIRED_DEFINITIONS
but I am not sure how to use it (nor if it is the right way at all).
How can I get CMake to correctly detect the presence of this function?
cmake pthreads
I a CMake project, I am trying to test for availability of pthread_setname_np()
. As for the headers, this function prototype only seems to be exposed if I #define _GNU_SOURCE
first.
Probably for this reason, simply doing
CHECK_FUNCTION_EXISTS(pthread_setname_np HAVE_PTHREAD_SETNAME_NP)
will not detect the function even though it is present. The documentation mentions CMAKE_REQUIRED_DEFINITIONS
but I am not sure how to use it (nor if it is the right way at all).
How can I get CMake to correctly detect the presence of this function?
cmake pthreads
cmake pthreads
asked Mar 23 at 18:37
user149408user149408
2,2721129
2,2721129
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Yes, CMAKE_REQUIRED_DEFINITIONS
is a correct way to test for this function. Here's an example of its use:
set(CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
CHECK_FUNCTION_EXISTS(pthread_setname_np HAVE_PTHREAD_SETNAME_NP)
unset(CMAKE_REQUIRED_DEFINITIONS)
You also probably want to read this: What does “#define _GNU_SOURCE” imply?
Thanks, you’re getting an upvote for this. Alas, it still doesn’t work—CMake does not find the function, despite it being defined in the header file. Could that have to do with the need to define_GNU_SOURCE
before including the header (as an answer to your linked question points out)?
– user149408
Mar 25 at 12:06
That's right - you have to define_GNU_SOURCE
in both cases: when you testing forpthread_setname_np
function and when you're using it within your code. Instead of defining it before including the header, you can also doadd_definitions(-D_GNU_SOURCE)
in CMakeLists.txt
– arrowd
Mar 25 at 12:10
CMake still isn’t picking it up andconfig.h
does not defineHAVE_PTHREAD_SETNAME_NP
. Same withadd_definitions
, or with the approach described in stackoverflow.com/q/13541788/2703209 (without touchingCMAKE_REQUIRED_LIBRARIES
as I don’t think I need any extra here).
– user149408
Mar 25 at 12:24
1
Take a look at logs located somewhere in your build directory. Specifically,CMakeFiles/
dir.
– arrowd
Mar 25 at 13:19
Thanks, that provided the hints I needed. Will post a new answer.
– user149408
Mar 25 at 23:05
add a comment |
This eventually worked for me (at least on Ubuntu 18.04, currently running CI for others):
list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
list(APPEND CMAKE_REQUIRED_LIBRARIES pthread)
CHECK_SYMBOL_EXISTS(pthread_setname_np pthread.h HAVE_PTHREAD_SETNAME_NP)
list(REMOVE_ITEM CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
Important: make sure you have a clean build environment, with no leftovers from previous builds. For cmake4eclipse, this means:
- Go to Project > Properties > C/C++ Build > CMake and check Force CMake to run with each build. (You can clear that option again after your first successful build.)
- Clean your project.
Appending the pthread
library proved necessary for me, otherwise it would not detect the function. The library name seems to be pthreads
on some systems (at least I see CMake testing for both); these systems may need further tweaks to detect the function.
CHECK_FUNCTION_EXISTS
instead of CHECK_SYMBOL_EXISTS
would have worked as well (I have tried both successfully).
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55317131%2fcmake-check-function-exists-for-a-function-requiring-define%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Yes, CMAKE_REQUIRED_DEFINITIONS
is a correct way to test for this function. Here's an example of its use:
set(CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
CHECK_FUNCTION_EXISTS(pthread_setname_np HAVE_PTHREAD_SETNAME_NP)
unset(CMAKE_REQUIRED_DEFINITIONS)
You also probably want to read this: What does “#define _GNU_SOURCE” imply?
Thanks, you’re getting an upvote for this. Alas, it still doesn’t work—CMake does not find the function, despite it being defined in the header file. Could that have to do with the need to define_GNU_SOURCE
before including the header (as an answer to your linked question points out)?
– user149408
Mar 25 at 12:06
That's right - you have to define_GNU_SOURCE
in both cases: when you testing forpthread_setname_np
function and when you're using it within your code. Instead of defining it before including the header, you can also doadd_definitions(-D_GNU_SOURCE)
in CMakeLists.txt
– arrowd
Mar 25 at 12:10
CMake still isn’t picking it up andconfig.h
does not defineHAVE_PTHREAD_SETNAME_NP
. Same withadd_definitions
, or with the approach described in stackoverflow.com/q/13541788/2703209 (without touchingCMAKE_REQUIRED_LIBRARIES
as I don’t think I need any extra here).
– user149408
Mar 25 at 12:24
1
Take a look at logs located somewhere in your build directory. Specifically,CMakeFiles/
dir.
– arrowd
Mar 25 at 13:19
Thanks, that provided the hints I needed. Will post a new answer.
– user149408
Mar 25 at 23:05
add a comment |
Yes, CMAKE_REQUIRED_DEFINITIONS
is a correct way to test for this function. Here's an example of its use:
set(CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
CHECK_FUNCTION_EXISTS(pthread_setname_np HAVE_PTHREAD_SETNAME_NP)
unset(CMAKE_REQUIRED_DEFINITIONS)
You also probably want to read this: What does “#define _GNU_SOURCE” imply?
Thanks, you’re getting an upvote for this. Alas, it still doesn’t work—CMake does not find the function, despite it being defined in the header file. Could that have to do with the need to define_GNU_SOURCE
before including the header (as an answer to your linked question points out)?
– user149408
Mar 25 at 12:06
That's right - you have to define_GNU_SOURCE
in both cases: when you testing forpthread_setname_np
function and when you're using it within your code. Instead of defining it before including the header, you can also doadd_definitions(-D_GNU_SOURCE)
in CMakeLists.txt
– arrowd
Mar 25 at 12:10
CMake still isn’t picking it up andconfig.h
does not defineHAVE_PTHREAD_SETNAME_NP
. Same withadd_definitions
, or with the approach described in stackoverflow.com/q/13541788/2703209 (without touchingCMAKE_REQUIRED_LIBRARIES
as I don’t think I need any extra here).
– user149408
Mar 25 at 12:24
1
Take a look at logs located somewhere in your build directory. Specifically,CMakeFiles/
dir.
– arrowd
Mar 25 at 13:19
Thanks, that provided the hints I needed. Will post a new answer.
– user149408
Mar 25 at 23:05
add a comment |
Yes, CMAKE_REQUIRED_DEFINITIONS
is a correct way to test for this function. Here's an example of its use:
set(CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
CHECK_FUNCTION_EXISTS(pthread_setname_np HAVE_PTHREAD_SETNAME_NP)
unset(CMAKE_REQUIRED_DEFINITIONS)
You also probably want to read this: What does “#define _GNU_SOURCE” imply?
Yes, CMAKE_REQUIRED_DEFINITIONS
is a correct way to test for this function. Here's an example of its use:
set(CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
CHECK_FUNCTION_EXISTS(pthread_setname_np HAVE_PTHREAD_SETNAME_NP)
unset(CMAKE_REQUIRED_DEFINITIONS)
You also probably want to read this: What does “#define _GNU_SOURCE” imply?
answered Mar 24 at 4:19
arrowdarrowd
23.3k45684
23.3k45684
Thanks, you’re getting an upvote for this. Alas, it still doesn’t work—CMake does not find the function, despite it being defined in the header file. Could that have to do with the need to define_GNU_SOURCE
before including the header (as an answer to your linked question points out)?
– user149408
Mar 25 at 12:06
That's right - you have to define_GNU_SOURCE
in both cases: when you testing forpthread_setname_np
function and when you're using it within your code. Instead of defining it before including the header, you can also doadd_definitions(-D_GNU_SOURCE)
in CMakeLists.txt
– arrowd
Mar 25 at 12:10
CMake still isn’t picking it up andconfig.h
does not defineHAVE_PTHREAD_SETNAME_NP
. Same withadd_definitions
, or with the approach described in stackoverflow.com/q/13541788/2703209 (without touchingCMAKE_REQUIRED_LIBRARIES
as I don’t think I need any extra here).
– user149408
Mar 25 at 12:24
1
Take a look at logs located somewhere in your build directory. Specifically,CMakeFiles/
dir.
– arrowd
Mar 25 at 13:19
Thanks, that provided the hints I needed. Will post a new answer.
– user149408
Mar 25 at 23:05
add a comment |
Thanks, you’re getting an upvote for this. Alas, it still doesn’t work—CMake does not find the function, despite it being defined in the header file. Could that have to do with the need to define_GNU_SOURCE
before including the header (as an answer to your linked question points out)?
– user149408
Mar 25 at 12:06
That's right - you have to define_GNU_SOURCE
in both cases: when you testing forpthread_setname_np
function and when you're using it within your code. Instead of defining it before including the header, you can also doadd_definitions(-D_GNU_SOURCE)
in CMakeLists.txt
– arrowd
Mar 25 at 12:10
CMake still isn’t picking it up andconfig.h
does not defineHAVE_PTHREAD_SETNAME_NP
. Same withadd_definitions
, or with the approach described in stackoverflow.com/q/13541788/2703209 (without touchingCMAKE_REQUIRED_LIBRARIES
as I don’t think I need any extra here).
– user149408
Mar 25 at 12:24
1
Take a look at logs located somewhere in your build directory. Specifically,CMakeFiles/
dir.
– arrowd
Mar 25 at 13:19
Thanks, that provided the hints I needed. Will post a new answer.
– user149408
Mar 25 at 23:05
Thanks, you’re getting an upvote for this. Alas, it still doesn’t work—CMake does not find the function, despite it being defined in the header file. Could that have to do with the need to define
_GNU_SOURCE
before including the header (as an answer to your linked question points out)?– user149408
Mar 25 at 12:06
Thanks, you’re getting an upvote for this. Alas, it still doesn’t work—CMake does not find the function, despite it being defined in the header file. Could that have to do with the need to define
_GNU_SOURCE
before including the header (as an answer to your linked question points out)?– user149408
Mar 25 at 12:06
That's right - you have to define
_GNU_SOURCE
in both cases: when you testing for pthread_setname_np
function and when you're using it within your code. Instead of defining it before including the header, you can also do add_definitions(-D_GNU_SOURCE)
in CMakeLists.txt– arrowd
Mar 25 at 12:10
That's right - you have to define
_GNU_SOURCE
in both cases: when you testing for pthread_setname_np
function and when you're using it within your code. Instead of defining it before including the header, you can also do add_definitions(-D_GNU_SOURCE)
in CMakeLists.txt– arrowd
Mar 25 at 12:10
CMake still isn’t picking it up and
config.h
does not define HAVE_PTHREAD_SETNAME_NP
. Same with add_definitions
, or with the approach described in stackoverflow.com/q/13541788/2703209 (without touching CMAKE_REQUIRED_LIBRARIES
as I don’t think I need any extra here).– user149408
Mar 25 at 12:24
CMake still isn’t picking it up and
config.h
does not define HAVE_PTHREAD_SETNAME_NP
. Same with add_definitions
, or with the approach described in stackoverflow.com/q/13541788/2703209 (without touching CMAKE_REQUIRED_LIBRARIES
as I don’t think I need any extra here).– user149408
Mar 25 at 12:24
1
1
Take a look at logs located somewhere in your build directory. Specifically,
CMakeFiles/
dir.– arrowd
Mar 25 at 13:19
Take a look at logs located somewhere in your build directory. Specifically,
CMakeFiles/
dir.– arrowd
Mar 25 at 13:19
Thanks, that provided the hints I needed. Will post a new answer.
– user149408
Mar 25 at 23:05
Thanks, that provided the hints I needed. Will post a new answer.
– user149408
Mar 25 at 23:05
add a comment |
This eventually worked for me (at least on Ubuntu 18.04, currently running CI for others):
list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
list(APPEND CMAKE_REQUIRED_LIBRARIES pthread)
CHECK_SYMBOL_EXISTS(pthread_setname_np pthread.h HAVE_PTHREAD_SETNAME_NP)
list(REMOVE_ITEM CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
Important: make sure you have a clean build environment, with no leftovers from previous builds. For cmake4eclipse, this means:
- Go to Project > Properties > C/C++ Build > CMake and check Force CMake to run with each build. (You can clear that option again after your first successful build.)
- Clean your project.
Appending the pthread
library proved necessary for me, otherwise it would not detect the function. The library name seems to be pthreads
on some systems (at least I see CMake testing for both); these systems may need further tweaks to detect the function.
CHECK_FUNCTION_EXISTS
instead of CHECK_SYMBOL_EXISTS
would have worked as well (I have tried both successfully).
add a comment |
This eventually worked for me (at least on Ubuntu 18.04, currently running CI for others):
list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
list(APPEND CMAKE_REQUIRED_LIBRARIES pthread)
CHECK_SYMBOL_EXISTS(pthread_setname_np pthread.h HAVE_PTHREAD_SETNAME_NP)
list(REMOVE_ITEM CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
Important: make sure you have a clean build environment, with no leftovers from previous builds. For cmake4eclipse, this means:
- Go to Project > Properties > C/C++ Build > CMake and check Force CMake to run with each build. (You can clear that option again after your first successful build.)
- Clean your project.
Appending the pthread
library proved necessary for me, otherwise it would not detect the function. The library name seems to be pthreads
on some systems (at least I see CMake testing for both); these systems may need further tweaks to detect the function.
CHECK_FUNCTION_EXISTS
instead of CHECK_SYMBOL_EXISTS
would have worked as well (I have tried both successfully).
add a comment |
This eventually worked for me (at least on Ubuntu 18.04, currently running CI for others):
list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
list(APPEND CMAKE_REQUIRED_LIBRARIES pthread)
CHECK_SYMBOL_EXISTS(pthread_setname_np pthread.h HAVE_PTHREAD_SETNAME_NP)
list(REMOVE_ITEM CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
Important: make sure you have a clean build environment, with no leftovers from previous builds. For cmake4eclipse, this means:
- Go to Project > Properties > C/C++ Build > CMake and check Force CMake to run with each build. (You can clear that option again after your first successful build.)
- Clean your project.
Appending the pthread
library proved necessary for me, otherwise it would not detect the function. The library name seems to be pthreads
on some systems (at least I see CMake testing for both); these systems may need further tweaks to detect the function.
CHECK_FUNCTION_EXISTS
instead of CHECK_SYMBOL_EXISTS
would have worked as well (I have tried both successfully).
This eventually worked for me (at least on Ubuntu 18.04, currently running CI for others):
list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
list(APPEND CMAKE_REQUIRED_LIBRARIES pthread)
CHECK_SYMBOL_EXISTS(pthread_setname_np pthread.h HAVE_PTHREAD_SETNAME_NP)
list(REMOVE_ITEM CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
Important: make sure you have a clean build environment, with no leftovers from previous builds. For cmake4eclipse, this means:
- Go to Project > Properties > C/C++ Build > CMake and check Force CMake to run with each build. (You can clear that option again after your first successful build.)
- Clean your project.
Appending the pthread
library proved necessary for me, otherwise it would not detect the function. The library name seems to be pthreads
on some systems (at least I see CMake testing for both); these systems may need further tweaks to detect the function.
CHECK_FUNCTION_EXISTS
instead of CHECK_SYMBOL_EXISTS
would have worked as well (I have tried both successfully).
answered Mar 25 at 23:36
user149408user149408
2,2721129
2,2721129
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55317131%2fcmake-check-function-exists-for-a-function-requiring-define%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown