Author Topic: Problems building sdcc c file with codeblocks  (Read 12770 times)

Offline yipinx

  • Single posting newcomer
  • *
  • Posts: 6
Problems building sdcc c file with codeblocks
« on: February 16, 2012, 07:36:16 pm »
Hi, I'm trying to compile a C source file with a z80 target (list.c in core/lib from http://www.contiki-os.org/ ). The file is part of a small protothreaded os and if compiled from the command line (msysgit) like this :
$ sdcc -mz80 -ID../../core -c list.c
it outputs all files as expected.

However, when in codeblocks, I right click on the file and choose from the menu 'build file' and after the message 'compiling core\lib\list.c' the help output of sdas assembler appears. I found a similar question in http://forums.codeblocks.org/index.php?topic=14970.0 but that fix doesn't appear to work for me, if I knew what to do with to begin with.

My setup on a winxpsp3 is as follows

D:\Code\msysgit (with mingw installed, codeblocks doesn't find it automagically but by hand it can be set and works as expected!)

D:\Code\sdcc (SDCC : mcs51/gbz80/z80/z180/r2k/ds390/pic16/pic14/TININative/ds400/hc08 3.1.0 #7066 (Nov 22 2011) (MINGW32))

D:\Code\codeblocks (10.05)

this is part of my .cbp file:

<Build>
   <Target title="MSX2 - Debug">
      <Option output="bin\Debug\LIBDSK" prefix_auto="1" extension_auto="1" />
      <Option object_output="obj\Debug\" />
      <Option type="1" />
      <Option compiler="sdcc" />
      <Compiler>
         <Add option="--out-fmt-ihx" />
         <Add option="--no-std-crt0" />
         <Add option="-mz80" />
         <Add option="--debug" />
         <Add option="--reserve-regs-iy --std-sdcc99" />
         <Add option="-DAUTOSTART_ENABLE" />
         <Add directory="platform\native" />
         <Add directory="cpu\native" />
         <Add directory="core" />
      </Compiler>
   </Target>
</Build>
<Compiler>
   <Add option="-Wall" />
</Compiler>

I tried to remove the Compiler option -Wall and restart codeblocks.. but that generates a unhandled exception.  :(

anyone any idea how to fix this, or am i doing something wrong maybe?

cheers,
Johan

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9702
Re: Problems building sdcc c file with codeblocks
« Reply #1 on: February 16, 2012, 07:40:16 pm »
On the console you have 2 compiler switches:
$ sdcc -mz80 -ID../../core -c list.c

In the project you have at 9 compiler switches:
      <Compiler>
         <Add option="--out-fmt-ihx" />
         <Add option="--no-std-crt0" />
         <Add option="-mz80" />
         <Add option="--debug" />
         <Add option="--reserve-regs-iy --std-sdcc99" />
         <Add option="-DAUTOSTART_ENABLE" />
         <Add directory="platform\native" />
         <Add directory="cpu\native" />
         <Add directory="core" />
      </Compiler>
You are comparing apples and oranges here. Fix your project setup.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline scarphin

  • Lives here!
  • ****
  • Posts: 644
Re: Problems building sdcc c file with codeblocks
« Reply #2 on: February 16, 2012, 08:45:50 pm »
First of all there is no '-Wall' switch for SDCC. That was my fault to include it which I thought was enabling 'all warnings'. In SDCC 'all warnings' are enabled by default so no '-Wall' switch.
Second I too think there must be something wrong with ur compiler switches.

Offline yipinx

  • Single posting newcomer
  • *
  • Posts: 6
Re: Problems building sdcc c file with codeblocks
« Reply #3 on: February 17, 2012, 03:56:41 am »
@macfly: my bad. I compiled the same c file again with the same compiler flags as in the .cbp file I previously posted but only the included core/ directory like so:
$ sdcc -mz80 --debug --out-fmt-ihx --no-std-crt0 --debug --reserve-regs-iy -std-sdcc99 -DAUTOSTART_ENABLE -ID:../../core -c list.c

I got this warning:

at 1: warning 118: option '-s' no longer supported  'use --code-loc instead'

but that is correct and should not be a problem for the build log I think.
To be sure, I removed the include paths from the codeblocks project file.

I tried the other way around as well, and removed all but -mz80 -D... and -I from the command line options and from the codeblocks project file but that didn't seem to help... even restarting codeblocks didn't do the trick (since it crashes a lot on these experiments :( ).

@scarphin: I know, --Wall is not part of sdcc. But it is defined below and outside the scope of the <Build/> element. I guess that suggests that it is a project wide compiler directive. But I don't know how to check that. The build log doesn't show how sdcc was invoked.

Offline scarphin

  • Lives here!
  • ****
  • Posts: 644
Re: Problems building sdcc c file with codeblocks
« Reply #4 on: February 17, 2012, 08:38:45 am »
What do u mean it is defined outside the scope? There shouldn't be any '-Wall' defined for an SDCC project or u'll get assembler error because it tries to pass the 'll' directive to the assembler which doesn't know what to do with it.

Offline yipinx

  • Single posting newcomer
  • *
  • Posts: 6
Re: Problems building sdcc c file with codeblocks
« Reply #5 on: February 17, 2012, 02:00:42 pm »
@scarphin: Yes I thought it was something like that, but I do not know any way to see how a file is compiled; what directives it is given. Anyway I found it. Its in the project's build options. The root node on the left pane shows you the project and its build targets. It is possible to set each build target individually but at the project level as well. And that is where it goes wrong.

Let me try to explain what I mean by taking the codeblock project file once again:

<CodeBlocks_project_file>
   <Project>
      <Option compiler="gcc" />    <!---- OUT OF THE BUILD AND TARGET SCOPE --!>
      <Build>
         <Target title="Debug">
            <Option compiler="gcc" />
            <Compiler />
         </Target>
         <Target title="MSX2 - Debug">
            <Option compiler="sdcc" />
            <Compiler />
         </Target>
      </Build>
      <Compiler> <!-- OUT OF THE BUILD AND TARGET SCOPE --!>
         <Add option="-Wall" />
      </Compiler>
   </Project>
</CodeBlocks_project_file>

The last compiler element in the project file is defined outside the build targets scope and even though the second target doesn't use gcc but sdcc, the projects compiler option -Wall will be executed, because it is defined at project wide scope and codeblocks doesn't check that the compiler for the build target is not the same as the project wide compiler. I think the problem can be easily solved when the project file is changed to something like this:

<CodeBlocks_project_file>
   <Project>
      <Option  />
      <Build>
         <Target title="Debug">
            <Option  />
            <Compiler select="gcc" />
         </Target>
         <Target title="MSX2 - Debug">
            <Option  />
            <Compiler select="sdcc" />
         </Target>
      </Build>
      <Compiler select="gcc">
         <Add option="-Wall" />
      </Compiler>
   </Project>
</CodeBlocks_project_file>

This way, at project level, one can set different compiler directives for each compiler and override them per build target.

Secondly, since I believe this IS a bug, one can first check the Option compiler attribute at project level to be the same as the current build target and include or not include the extra compiler options when the target compilers(!!) are the same. (This is not happening right now)

cheers,
Johan


« Last Edit: February 17, 2012, 02:20:09 pm by yipinx »

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7256
Re: Problems building sdcc c file with codeblocks
« Reply #6 on: February 17, 2012, 02:13:39 pm »
You can either remove the project-wide -Wall or change the "Policy:" dropdown of the target(s) to "Use target options only".

Offline yipinx

  • Single posting newcomer
  • *
  • Posts: 6
Re: Problems building sdcc c file with codeblocks
« Reply #7 on: February 17, 2012, 02:15:57 pm »
@jens: :) thanks, will change it right away!