有什么办法可以创建一个“.O”吗? “.C”中没有 main() 函数的文件文件

发布于 2024-11-18 02:10:33 字数 527 浏览 6 评论 0原文

在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等...?

请问...

我见过这个问题吗?

可以编译任何 .c隔离文件(即没有主文件?)

但我没有找到答案......

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

沐歌 2024-11-25 02:10:33

对于几乎所有编译器,-c 都应该默认生成 .o 文件。您可以使用与 sun 编译器相同的语法:gcc 也支持 -o

这应该可以正常工作:

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

请注意,在 Windows 上,.o 文件通常被命名为 .obj 作为视觉约定:坚持该约定可能是个好主意。

我认为如果在命令行中使用 Visual Studio 编译器,则必须使用 /c 进行编译,如 MS 网站

最后,如果您正在编译 C++,您应该使用 g++ 而不是 gcc。

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.

肩上的翅膀 2024-11-25 02:10:33

gcc -c file.c 应该可以正常工作吗?

gcc -c file.c should work just fine?

美胚控场 2024-11-25 02:10:33

我所知道的每个 C 编译器都可以识别这种编译模式的 -c 标志。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文