开发者

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

开发者 https://www.devze.com 2023-03-16 03:44 出处:网络
In linux : C++ 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 is开发者_如何学运维olation (that is, without a main?)

but i didn't find the answer ...


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.


gcc -c file.c should work just fine?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消