Search code examples
c++windowslinuxg++cc

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


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 ...


Solution

  • 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.