1

In linux : C++

Is there any way is ther to create a ".O" file without main() function in ".C" file .

iam using

     "cc -c file.c -o file.o  " with sun compiler  
     " gcc -Wall -c file.c " with g++ compiler

may i know

1) what command we need to use for with EDG compiler and any other C++ compielrs in LINUX

2) In windows may i know for any compilers ..even g++,cc,intel,etc ...?

please ...

i have seen this question ?

Possible to compile any .c file in isolation (that is, without a main?)

but i didn't find the answer ...

Community
  • 1
  • 1
user751747
  • 1,129
  • 1
  • 8
  • 17

3 Answers3

1

gcc -c file.c should work just fine?

Jesus Ramos
  • 22,940
  • 10
  • 58
  • 88
1

Every C compiler I am aware of recognizes the -c flag for this mode of compilation.

1

For almost any compiler, -cshould produce a .o file by default. You can use the same syntax as with your sun compiler : -o is supported as well by gcc.

This should work just fine:

 gcc -Wall -c file.c -o file.o

Note that on windows, .ofiles are usually named .obj as a visual convention : it might be a good idea to stick to that convention.

I think that if suing visual studio compiler in command line, you must use /c to make it compile, as defined on MS web site

Last, if you're compiling C++, you should use g++ instead of gcc afaik.

Bruce
  • 7,094
  • 1
  • 25
  • 42