compiling a c file with functions and c++ file with main together

Hi all,

I have my functions defined in func.c file and i am using the functions from func.c in my main.cpp

can i compile main.cpp and func.c files together?

what works for me is, compile only func.c first, get a func.o and then
g++ main.cpp func.o ie.,

gcc -c func.c
g++ main.cpp func.o

instead i would like to do g++ main.cpp func.c at a time if possible? can i compile and link c and c++ files together?

When i try to do, g++ main.cpp func.c, I get

/tmp/cchUrHYq.o: In function `main':
main.cpp:(.text+0xb3): undefined reference to `sub'
collect2: ld returned 1 exit status


Topic archived. No new replies allowed.