- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi all,
I am having a problem building a project when I try to use a .c source and .h header file in the project. When I build the project with all the code in the main.c file, everything works fine. However, when I move all the code except for int main() into a header and and c file and then add them to the project, I receive the following error:
.\CortexM3\ARM_GCC_493\Debug\main.o:(.data+0x10): multiple definition of `readPtr'
.\CortexM3\ARM_GCC_493\Debug\RMISensor.o:(.data+0x10): first defined here
collect2.exe: error: ld returned 1 exit status
The command 'arm-none-eabi-gcc.exe' failed with exit code '1'.
I actually get those first two lines a bunch of times for some of the variables I defined in the header file but I just included one as an example. It seems as though the main.o file is trying to define these variables despite it being removed from main.c. I've tried everything including completely remaking the project from scratch but haven't found a solution. I am using PSoC Creator 3.3.
Thanks for the help.
Nick
Solved! Go to Solution.
- Labels:
-
PSoC 5LP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The error is quite clear: you defined variables in a .h file, but you may only declare them there.
Copy all your variables declaration into the appropriate .c file
In the .h: change the variable definitions to a declaration by prepending them with "extern" and removing any initialization.
To distinguish the vocables:
declaration does not allocate any space, it only tells the compiler that something exists somewhere.
definition allocates space and instantiates the object, telling the compiler what and where the object is.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Welcome in the forum, Nick!
Can you please post your complete project, so that we all can have a look at all of your settings. To do so, use
Creator->File->Create Workspace Bundle (minimal)
and attach the resulting file.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The error is quite clear: you defined variables in a .h file, but you may only declare them there.
Copy all your variables declaration into the appropriate .c file
In the .h: change the variable definitions to a declaration by prepending them with "extern" and removing any initialization.
To distinguish the vocables:
declaration does not allocate any space, it only tells the compiler that something exists somewhere.
definition allocates space and instantiates the object, telling the compiler what and where the object is.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
hii, i am having a build error device.h please help me to remove it
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Welcome in the forum.
Can you please post your complete project, so that we all can have a look at all of your settings. To do so, use
Creator->File->Create Workspace Bundle (minimal)
and attach the resulting file.
Bob