Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

ModusToolbox™ General Forum Discussions

Kenshow
Level 8
Level 8
50 solutions authored 25 solutions authored 10 solutions authored

Hi,

How do I set custom compile options of gcc for only one file in Modus Toolbox2.1?

For example, the active of build configuration is "release" but only the mail.c file set non-optimized compilation options like -g.

I want to set different compilation options only for the main.c file.

Thanks,

Kenshow

0 Likes
1 Solution
MotooTanaka
Level 9
Level 9
First comment on KBA 1000 replies posted 750 replies posted

Hi,

Can you try using "pragma"

"#pragma GCC optimization_level n" may provide the service you want.

Refer to

optimization_level

https://gcc.gnu.org/onlinedocs/gcc/Function-Specific-Option-Pragmas.html

moto

View solution in original post

9 Replies
Rakshith
Moderator
Moderator
Moderator
1000 replies posted 750 replies posted 500 replies posted

Hi NoTa_4591161​,

As of now, there is no direct way to do this. I will be raising an internal ticket to track this issue so that the internal teams can evaluate the request.

As a workaround you can follow these steps for now:

1. Using the modus shell, perform a verbose build using the command 'make build VERBOSE=1'. You can refer to this blog to know about modus shell - Build, Program and Debug your ModusToolbox Application using the Command Line Interface (CLI)

2. Copy the compilation command of the required source file to a text file. For simplicity, I will consider main.c

3. Modify the arguments and run the compilation command directly on the modus shell to create a new main.o file.

4. Run the build again to run the linker.

Please let me know if this works for you.

Thanks and Regards,

Rakshith M B

Thanks and Regards,
Rakshith M B
0 Likes

Hi Rakshith,

Thank you for your suggestions.

Well, I've never used LCI or VSCODE, so please give me time to check this.

Best Regards,
Kenshow

0 Likes

Hello Len,

I've picked up main.c file as an example, but my question is how to change the options for a particular file. Although your approach based on the Volatile Declaration is valid, it is a little different from this thread. But, thank you for your advice.

Regards,

Kenshow

0 Likes

Hello Motoo,

I think that using pragma is effective for optimization. However, this time I would like to use for the build option, so I will consider modifying the makefile.

Thanks for your advice.

Regards,

Kenshow

0 Likes

Hi Rakshith,

I tried your suggestion but realized that it could be done with Modus IDE.

Copy the project, change the options in the destination project, and use that object in the original project. Delete the original source files and build the original.

This time it was easier to use #pragma. However, I would like to be able to set custom options for each file in the Modus IDE.

Thanks,

Kenshow

0 Likes
Rakshith
Moderator
Moderator
Moderator
1000 replies posted 750 replies posted 500 replies posted

Hi NoTa_4591161​,

Thank you for sharing.

Yes, I agree with you. All the different ways suggested here are workarounds. I have already raised an internal ticket to add this feature into the build system so that this request can be tracked.

Hope this helps.

Best regards,

Rakshith M B

Thanks and Regards,
Rakshith M B
Len_CONSULTRON
Level 9
Level 9
500 solutions authored 1000 replies posted 750 replies posted

Kenshow,

It looks like you are trying to prevent optimization on the file mail.c.  I'm assuming this is because you are trying to debug code in this file.(?)

I believe the gcc compiler has some compile-time keyword parameters to disable types of optimization from within the module itself.

For example, using the volatile keyword on a variable (especially a local variable) will prevent the compiler from only making it available in CPU registers.  It forces the variable to be accessed in RAM (or in registers).

Len

Len
"Engineering is an Art. The Art of Compromise."
0 Likes
MotooTanaka
Level 9
Level 9
First comment on KBA 1000 replies posted 750 replies posted

Hi,

Can you try using "pragma"

"#pragma GCC optimization_level n" may provide the service you want.

Refer to

optimization_level

https://gcc.gnu.org/onlinedocs/gcc/Function-Specific-Option-Pragmas.html

moto

Hi,

I just came up with this idea.

Since ModusToolbox 2.1 uses "Makefile", can't we add lines something like below?

==============

main.o : main.c

$(CC) -g -c main.c

==============

moto