Author Topic: How to define a Variable value frome shell cmd  (Read 1175 times)

Offline ccdric

  • Multiple posting newcomer
  • *
  • Posts: 24
How to define a Variable value frome shell cmd
« 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

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7805
    • My Best Post
Re: How to define a Variable value frome shell cmd
« Reply #1 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.
« Last Edit: September 25, 2025, 02:43:15 pm by stahta01 »
C Programmer working to learn more about C++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline ccdric

  • Multiple posting newcomer
  • *
  • Posts: 24
Re: How to define a Variable value frome shell cmd
« Reply #2 on: Yesterday at 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)