Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: ccdric on September 25, 2025, 10:56:24 am

Title: How to define a Variable value frome shell cmd
Post by: ccdric on September 25, 2025, 10:56:24 am
Hi Everybody,
I intend to define a variable in CB project from shell cmd return value.
example :
Quote
PYBIND_INCLUDE=$(python -m pybind11 --includes)
of course $(something) use something as a variable label in C::B project, unlike executed in the shell environment.

Does anyone have any ideas?
have a nice day
Title: Re: How to define a Variable value frome shell cmd
Post by: stahta01 on September 25, 2025, 02:40:34 pm
The tilted tic does that in places in CB   [`]  the tic between the square brackets.
Edit you need one at both the start and end of the command.
Edit2: I have never used it to define a variable; so, not sure where all it works.
I have used it in both compiler and linker extra setting.

Tim S.
Title: Re: How to define a Variable value frome shell cmd
Post by: ccdric on September 26, 2025, 09:52:32 am
Thanks stahta01 :
it works halfway  :D
in CodeBlocks_project_file/Project/Build/Environment
add 2 variables :
Code
    <Variable name="PYBIND_INCLUDES" value="`python -m pybind11 --includes`" />
    <Variable name="PYBIND_EXTENTION" value="`python -m pybind11 --extension-suffix`" />
in CodeBlocks_project_file/Project/Build/Target/Compiler
add this :
Code
<Add option="$(PYBIND_INCLUDES)" />
(this is the half part that works fine  :) )

But here it doesn't works :( :
in CodeBlocks_project_file/Project/Build/Target/Option/@output
Code
 <Option output="bin/Debug/trie$(PYBIND_EXTENTION)" ... >

the var is literally copied in the link cmd :
Code
g++-13 -shared obj/Debug/src/mod1.o obj/Debug/src/mod2.o  -o "bin/Debug/libmylib`python -m pybind11 --extension-suffix`.so" -m64 
Perhaps there is a better way for that second part ?

(I try ton compile c++ lib for use it in python. It's new for me. I 'll hive probably other question how to parameterize C::B to fit in python env)