有什么办法可以创建一个“.O”吗? “.C”中没有 main() 函数的文件文件
在linux中:C++
有没有办法在“.C”文件中创建一个没有main()函数的“.O”文件。
我正在使用
"cc -c file.c -o file.o " with sun compiler
" gcc -Wall -c file.c " with g++ compiler
我可以知道
1)我们需要在LINUX中使用EDG编译器和任何其他C ++编译器使用什么命令
2)在Windows中我可以知道任何编译器..甚至g ++,cc,intel等...?
请问...
我见过这个问题吗?
但我没有找到答案......
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 ...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对于几乎所有编译器,
-c
都应该默认生成.o
文件。您可以使用与 sun 编译器相同的语法:gcc 也支持-o
。这应该可以正常工作:
请注意,在 Windows 上,
.o
文件通常被命名为.obj
作为视觉约定:坚持该约定可能是个好主意。我认为如果在命令行中使用 Visual Studio 编译器,则必须使用
/c
进行编译,如 MS 网站最后,如果您正在编译 C++,您应该使用 g++ 而不是 gcc。
For almost any compiler,
-c
should 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:
Note that on windows,
.o
files 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 siteLast, if you're compiling C++, you should use g++ instead of gcc afaik.
gcc -c file.c 应该可以正常工作吗?
gcc -c file.c should work just fine?
我所知道的每个 C 编译器都可以识别这种编译模式的
-c
标志。Every C compiler I am aware of recognizes the
-c
flag for this mode of compilation.