Error during build of PSoC 5 project when using .c and .h files

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

cross mob
Anonymous
Not applicable

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

0 Likes
1 Solution
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

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

View solution in original post

0 Likes
5 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

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

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

Hi Bob,

   

Thanks for the reply. The project is attached.

   

Nick

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

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

0 Likes
Anonymous
Not applicable

hii, i am having a build error device.h please help me to remove it

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

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

0 Likes