Author Topic: How to force CB compile sequence (generally) to mimic makefile on STM32F4  (Read 19080 times)

Offline philcal

  • Single posting newcomer
  • *
  • Posts: 8

How do you get CB, to invoke compiler on group of srcfiles and object copy, rather than individually compile each and then link.

I am trying to compile a simple STM32F4 project from a net example. The guts of the makefile is only two lines yet I cannot seem to be able to replicate this natively in CB and get linker error.

I think the different compile sequences is at the root cause.

####################################
codeblocks sequence:-
 
((compile individually))
arm-none-eabi-gcc .....flags..... -c firstsrcfile.c -o firstsrcfile.o
.
.
arm-none-eabi-gcc .....flags..... -c an-asm-file.s -o lastsrcfile.o

((link))
arm-none-eabi-ld  list-of-source-objectfilesfrom above -s -Tstm32_flash.ld  ....libraries

((resultingerror))
main.o uses VFP register arguments, cbjh does not
((note: in CB compiler toolchain executables settings arm-none-eabi-ld is not set (arm-none-eabi-objcopy is set for static linker) yet somehow CB invokes ld and its this part that is causing the grief))

##################################
makefile sequence:- 

((compile combined))
arm-none-eabi-gcc .....flags..... the-list-of-c-source-objectfiles   -o main.elf ....libraries
arm-none-eabi-objcopy -O binary main.elf main.bin
((successfully links))
((relevant makefile command which does this firstline is  arm-none-eabi-gcc $(CFLAGS) $^ -o $@ ...libraries
($^ being a list of source files, $@ corresponding objectfile )))


How does one achieve the second method sequence in Codeblocks?   

I suspect an answer might be to point to a script, but should this be necessary for a simple project? If anyone cares to answer are there any aailable general methods that one can  adapt a makefile into the CB environment? As a noobie I have noted advice to avoid using the makefile approach. I cannot agree more after observing the cumbersome inpenetratable makefile code, but?

PS I started another topic on this (with 15 reads) but deleted it as I now suspect  the cause of the problem was the above.

the example code I'm trying to compile is from git clone git://github.com/jeremyherbert/stm32-templates.git
http://jeremyherbert.net/get/stm32f4_getting_started

Offline philcal

  • Single posting newcomer
  • *
  • Posts: 8
update:      "the-list-of-c-source-objectfiles" should read  "the-list-of-c-source-asm" files ie a one pass compile

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post

makefile sequence:- 

((compile combined))
arm-none-eabi-gcc .....flags..... the-list-of-c-source-objectfiles   -o main.elf ....libraries
arm-none-eabi-objcopy -O binary main.elf main.bin
((successfully links))
((relevant makefile command which does this firstline is  arm-none-eabi-gcc $(CFLAGS) $^ -o $@ ...libraries
($^ being a list of source files, $@ corresponding objectfile )))


How does one achieve the second method sequence in Codeblocks?   

Step 1: Learn how the Compiler and Linker works using the normal two step process (compile then link as the two steps)
Step 2: Write the compile step on the command line so it works
Step 3: Write the linker step on the command line so it works
Step 4: Write the objcopy step on the command line so it works

Step 5: Post the commands that work on the command line so you can ask how to do this using Code::Blocks.

My guess is the command use in Step 4 will be a post build step.

Till I or someone else sees the commands for steps 2 and 3; no one but an  arm-none-eabi-gcc user can answer the question except with guesses.

The more knowledgeable they are about GCC the better the guesses will be.

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline philcal

  • Single posting newcomer
  • *
  • Posts: 8
Thanks for your reply but I think you have missed my point.  I was trying to find a general solution  as indicated in the topic subject and nothing specific to the arm compiler. However you did  make me see the issue more clearly.

In essence I think I have a combined compilerANDlinker rather than two separate components, Presumably the linker bit is invoked when passing more than one source file to it.


Step 1: Learn how the Compiler and Linker works using the normal two step process (compile then link as the two steps)
Step 2: Write the compile step on the command line so it works
Step 3: Write the linker step on the command line so it works
Step 4: Write the objcopy step on the command line so it works

Tim S.

Step1&2  As above I believe I have a combined program. One command line call passing it source files produces a single main.elf output. I have included the command below FWIW.

Step3  There is no explicit linker call.  As an aside, trawling thru the terminal output of the above command with verbose output I did not find any reference to the stand alone arm linker arm-none-eabi-ld. 

Step4 This is furphy as it is involves no linking  step and my problem occurs before this.

So unless I'm wrong it seems in my CB project I need to pass a group of files to the "compiler" and not have CB process individually -and not specifically call the "linker". I now see  part of my solution maybe to eliminate any linker executable in my CB toolchain list but I still need to pass a list of files.



single command line command produces a single output file:   arm-none-eabi-gcc -g -v -O2 -Wall -Tstm32_flash.ld  -mlittle-endian -mthumb -mcpu=cortex-m4 -mthumb-interwork -mfloat-abi=hard -mfpu=fpv4-sp-d16 -Iinc -Ilib -Ilib/inc  -Ilib/inc/core -Ilib/inc/peripherals  src/system_stm32f4xx.c src/main.c src/stm32f4xx_it.c lib/startup_stm32f4xx.s -o main.elf -Llib -lstm32f4

Extract of my CB default.conf file:
            <C_COMPILER>
               <str>
                  <![CDATA[arm-none-eabi-gcc]]>
               </str>
            </C_COMPILER>
            <CPP_COMPILER>
               <str>
                  <![CDATA[arm-none-eabi-g++]]>
               </str>
            </CPP_COMPILER>
            <LINKER>
               <str>
                  <![CDATA[arm-none-eabi-gcc]]>
               </str>
            </LINKER>
            <LIB_LINKER>
               <str>
                  <![CDATA[arm-none-eabi-objcopy]]>
               </str>
            </LIB_LINKER>
            <DEBUGGER_CONFIG>
               <str>
                  <![CDATA[gdb_debugger:Default]]>
               </str>





Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
If you are NOT will to put forth the effort to learn how your compiler works; DO NOT expect any help from me.

If you wish to use a makefile use one; if you wish to use the normal CB build system use it.
You CAN NOT do both in the same CB project.

Tim S.
« Last Edit: April 21, 2013, 05:09:46 am by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline osdt

  • Multiple posting newcomer
  • *
  • Posts: 63
As stahta01 posted:
Step 1: Learn how the Compiler and Linker works using the normal two step process (compile then link as the two steps)
Step 2: Write the compile step on the command line so it works
Step 3: Write the linker step on the command line so it works
Step 4: Write the objcopy step on the command line so it works

Step 5: Post the commands that work on the command line so you can ask how to do this using Code::Blocks.

This is the first real information to work with:
single command line command produces a single output file:   arm-none-eabi-gcc -g -v -O2 -Wall -Tstm32_flash.ld  -mlittle-endian -mthumb -mcpu=cortex-m4 -mthumb-interwork -mfloat-abi=hard -mfpu=fpv4-sp-d16 -Iinc -Ilib -Ilib/inc  -Ilib/inc/core -Ilib/inc/peripherals  src/system_stm32f4xx.c src/main.c src/stm32f4xx_it.c lib/startup_stm32f4xx.s -o main.elf -Llib -lstm32f4

Next step: compile + link:
Code
# compile
arm-none-eabi-gcc -c -g -v -O2 -Wall -mlittle-endian -mthumb -mcpu=cortex-m4 -mthumb-interwork -mfloat-abi=hard -mfpu=fpv4-sp-d16 -Iinc -Ilib -Ilib/inc  -Ilib/inc/core -Ilib/inc/peripherals src/system_stm32f4xx.c src/main.c src/stm32f4xx_it.c lib/startup_stm32f4xx.s

#link
arm-none-eabi-gcc -Tstm32_flash.ld system_stm32f4xx.o main.o stm32f4xx_it.o startup_stm32f4xx.o -o main.elf -Llib -lstm32f4

... and post the result.

Edit:
...
((link))
arm-none-eabi-ld  list-of-source-objectfilesfrom above -s -Tstm32_flash.ld  ....libraries

((resultingerror))
main.o uses VFP register arguments, cbjh does not
((note: in CB compiler toolchain executables settings arm-none-eabi-ld is not set (arm-none-eabi-objcopy is set for static linker) yet somehow CB invokes ld and its this part that is causing the grief))
If it is not set for the toolchain, you'll probably find it in 'Advanced compiler options->Command line macros'. Use $linker instead of 'arm-none-eabi-ld'

- osdt

« Last Edit: April 21, 2013, 11:40:45 pm by osdt »

Offline philcal

  • Single posting newcomer
  • *
  • Posts: 8
Thanks osdt,
I really needed some encouragement after Tims reply. He is obviously well intentioned and I'm sorry I caused him grief and lose patience. He actually helped me a year ago when I was trying to program avr's as a raw beginner

However I think what we are now discussing is compiler specific and thus not really CB forum related. So  no further posts on this from me.  However I'd like to continue by PM after digesting the hints you posted  if you would be so kind . 

Now, my asking whether CB could invoke this "combined"compiler command I posted I think is still reasonable but my motive was flawed. I was attempting a  work around to substitute for the conventional compile link approach which I couldn't get going.


My general approach to programing is to initially get somebody's simple project going that is  known to work  and expand from there. I'm the first to admit I'm not knowledgeable enough to start from scratch but contrary to Tims impression  know what the linker is supposed to do. A solid two weeks in on this microprocessor  and I still cant get an environment suitable for  the equivalent  humble 'hello world'. Since I've never found a CB .cbp project example on the net for STM32  I was trying to work back from  a makefile. I'd love to obtain a complete environmental setup -CB OpenOCD the works! and was even  considering how to put out a 'bounty'.

Offline Aelxx

  • Multiple posting newcomer
  • *
  • Posts: 10
Have you looked at emIDE (http://emide.org/) ?
It's C::B fork with goal to compile ARM-NONE-EABI projects. I use it with STM32F405/407.