undefined reference to main

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

cross mob
Anonymous
Not applicable

I'm currently working on a BLE project with PSoC 4. Since today everything worked fine. But now I'm facing the error "undefined reference to main" every time I compile my project. Didn't change anything on the project or code since the last successful compilation.

Hope you can help me.

 

0 Likes
1 Solution
Anonymous
Not applicable

I fixed it.

main.c wasn't compiled at all. So the linker didn't find the object file main.o. After removing main.c from the project and adding it again, it was compiled properly. But then I got the same problem for all the other files in my project. So I had to remove and add all the other files, too.

   

This seems to be a bug in the IDE, that should be further investigated.

View solution in original post

0 Likes
6 Replies
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received
        Are you missing your int main; function ? It could have been removed in an edit. Please post your code so we can check it.   
0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

You specified in main.c

   

extern int main(void)

   

Get rid of the "extern"

   

 

   

Bob

0 Likes
Anonymous
Not applicable

That doesn't change anything. In C extern is declared implicit.

0 Likes
Anonymous
Not applicable

I fixed it.

main.c wasn't compiled at all. So the linker didn't find the object file main.o. After removing main.c from the project and adding it again, it was compiled properly. But then I got the same problem for all the other files in my project. So I had to remove and add all the other files, too.

   

This seems to be a bug in the IDE, that should be further investigated.

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

This issue probably has to do with the way you add the files to the project. When you right click on your original main.c file, the option to compile it is grayed out. Same for the other .c files.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

I added all files by right-clicking on the project -> Add -> Existing item/New item. But it just worked fine until yesterday. Didn't add any new files. It seems that something broke my project file.

0 Likes