User forums > Using Code::Blocks

Setting #define for project (not in Source Code)

<< < (2/3) > >>

stahta01:
I will try to find my custom makefile project solution; note: It may or may not work for you.

Edit: Link to Wiki page that might help you http://wiki.codeblocks.org/index.php/Code::Blocks_and_Makefiles

It been several months to possibly years since; I used my custom makefile project solution, it might no longer work.

But, you should be still able to add options to the make command to solve your problem with defines.

Tim S.

stahta01:
Edit: See "Make" Commands tab.

I added CPPFLAGS="-DWINVER=0x0601" to define WINVER with the value 0x0601.

This will NOT work with all makefiles; but, should work with most well written ones.

Tim S.

The commands below are from a CB Project I created to build wxWidgets.


--- Code: ---$make -f $makefile MONOLITHIC=0 SHARED=1 BUILD=debug CPPFLAGS="-DWINVER=0x0601"

--- End code ---


--- Code: ---$make -f $makefile MONOLITHIC=0 SHARED=1 BUILD=debug CPPFLAGS="-DWINVER=0x0601" $file

--- End code ---

oBFusCATed:
@duderino65:
Please describe your problem with more details, the current description just causes confusion!
Where does C::B can't see your derine?
It seems it is not related to building, but something in the editor.
Is your problem that C::B's editor greys out some parts of the code?
Or is it that code completion doesn't see some functions/variable/marco guarded by defines?

sodev:
This problem sounds quite familiar to me, im pretty sure his problem is code completion. For code completion to work it needs to know the current compiler configuration. He is using an external Makefile and this configures the compiler, in his case it especially sets certain defines. Apparently codeblocks doesnt read the makefile and therefore code completion runs with a different compiler configuration, especially it doesnt know these defines and code completion will evaluate all #ifdefs querying these defines to false and e.g. show the code parts as disabled.

The problem is actually more complicated, because defines are not the only information code completion needs, e.g. it makes a huge difference if gcc runs in c++ 11 mode or not. I dont know how code completion in CodeBlocks solves this, i have the same problem in Eclipse when using an external Makefile. But in Eclipse, even when using an external Makefile, you can still set compiler defines, include paths and compiler command line parameters so that its code completion can query the compiler internal defines and other settings. But in CodeBlocks these settings are all missing for a custom Makefile project, so he cant adjust the compiler configuration that code completion sees to the one that his makefile actually uses to compile the code.

In his case adjusting the global compiler configuration doesnt work because his project uses different settings per target, he needs the target specific settings to be available.

duderino65:
Hi all,

@Tim S.: Thanks for your big effort. I'm really sorry, I didn't describe my problem very well.

As "sodev" already wrote, my problem is that CB disables some code parts which normally are active for this particular target. So it is harder to get / see these code parts which is somehow painful at programming. I thought it would be possible somehow to add such a define for the particular project. If this is not possible, it is not a show stopper. Maybe I can adjust the highlighting of the editor.

Thanks for your help.

Kind regards
Andi

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version