Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22016

Why am I getting a "duplicate symbol" error for my functions in C?

$
0
0

I have three C files, main.c, function1.c, and function2.c. I compile them using gcc -o main main.c function1.c function2.c. I have a helper function helper() defined in function1.c. So function1.c looks like this:

void helper();

void function() {
...
}

void helper() {
...
}

However, when I try to define helper() the same way in function2.c, it gives me the error "duplicate symbol '_helper'". I assume this is because I've compiled function1.c and function2.c together, so function2.c is aware of the definition of helper() in function1.c, but I can't call helper() in function2.c. I also don't want to define helper() in its own file because I may end up writing many such helper files. What would be ideal is if I could have a helper.c file that contained functions helper1(), helper2(), etc, all accessible from function1.c and function2.c. Does anyone know how to do that, or a better alternative?


Viewing all articles
Browse latest Browse all 22016

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>