Jump to content
Sign in to follow this  

Duplicate Global Variable Error With Boostc Linker

Recommended Posts

Bug description:

If two source modules have global variables with the same name, the linker complains about a duplicate variable.


Steps to reproduce:

1.) Create a new project

2.) Add a main.c file to the project with the following code

char x;

void main()


3.) Add a other.c file to the project with the following code

char x;

void test()


4.) Compile the project using BoostC

5.) Notice the linker error message


Expected behavior:

The linker should allow for each C module to have their own set of global variables that might have the same name because the declared variables were declared at module scope.


Is the problem 100% reproduceable:



PicAntIDE version: PicAndIDE version

Compiler: BoostC

Compiler version: 1.0 Alpha


OS: Windows XP




Share this post

Link to post
Share on other sites

Thanks for the report but this is not a bug. If you try to do same under MS Visual C++ it will also complain:


test.obj : error LNK2005: "char x" (?x@@3DA) already defined in main.obj


You need to declare these global variables as 'static' (or make 'static' at least one of them).




Share this post

Link to post
Share on other sites

Yes, you are correct, I should have tested it in MSVC++ before submitting it.


However, I still have a question. How then, do we include <system.h> in two different C modules? That is really how I came upon this problem. Once you include <system.h> in two different C modules, you get duplicate variable errors because none of the register variables are declared as static. Perhaps in <system.h>, the registers should be declared as static?

Share this post

Link to post
Share on other sites

Ahh this is a beauty of variables with fixed addresses ;) Since they are already located they don't collide even if declared in different source files.




Share this post

Link to post
Share on other sites

Gotcha, however, if this is the case, how come the following code does not link because the linker says that there are duplicate variables.


Make a main.c source file with the following code:

#include <system.h>

void main()



Then, make another test.c source file with the following code:

#include <system.h>

void test()


Add both files to a new project and compile. It compiles fine, but will not link without errors. If I understand you correctly, the linker should not fail because the variables within the system.h file are fixed address variables. However, the linker does fail.


Here is the linker output:

BoostLink Optimizing Linker Version 1.0 Alpha

Copyright© 2004 Pavel Baranov

Copyright© 2004 David Hobday

Duplicate global var:indf

Duplicate global var:tmr0

Duplicate global var:pcl

Duplicate global var:status

Duplicate global var:fsr

Duplicate global var:porta

Duplicate global var:portb

Duplicate global var:portc

Duplicate global var:pclath

Duplicate global var:intcon

Duplicate global var:pir1

Duplicate global var:pir2

Duplicate global var:tmr1l

Duplicate global var:tmr1h

Duplicate global var:t1con

Duplicate global var:tmr2

Duplicate global var:t2con

Duplicate global var:sspbuf

Duplicate global var:sspcon

Duplicate global var:ccpr1l

Duplicate global var:ccpr1h

Duplicate global var:ccp1con

Duplicate global var:rcsta

Duplicate global var:txreg

Duplicate global var:rcreg

Duplicate global var:ccpr2l

Duplicate global var:ccpr2h

Duplicate global var:ccp2con

Duplicate global var:adresh

Duplicate global var:adcon0

Duplicate global var:option_reg

Duplicate global var:trisa

Duplicate global var:trisb

Duplicate global var:trisc

Duplicate global var:pie1

Duplicate global var:pie2

Duplicate global var:pcon

Duplicate global var:sspcon2

Duplicate global var:pr2

Duplicate global var:sspadd

Duplicate global var:sspstat

Duplicate global var:txsta

Duplicate global var:spbrg

Duplicate global var:cmcon

Duplicate global var:cvrcon

Duplicate global var:adresl

Duplicate global var:adcon1

Duplicate global var:eedata

Duplicate global var:eeadr

Duplicate global var:eedath

Duplicate global var:eeadrh

Duplicate global var:eecon1

Duplicate global var:eecon2



Exit code was -1. [No error.]

Removing target: test.hex

Failed to locate output file 'test.hex'





Please shine some light on this, thanks.

Share this post

Link to post
Share on other sites
Guest Dave

You are correct, currently this fails but should not - it should work as per Pavels expectation.


Totally my mistake ;)


I have fixed linker, it will be released soon with this fix.





Share this post

Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Create New...