在MinGW中手动链接标准库 [英] manually link standard library in MinGW

查看:50
本文介绍了在MinGW中手动链接标准库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难让MinGW识别CSFML库.我不得不使用链接器手动链接每个库.现在,我没有从简单的gcc调用自动链接的标准库.

I had some trouble getting MinGW to recognise libraries for CSFML. I've had to manually link each library using the linker. Now I dont have the standard library that gets linked automatically from a simple gcc call.

bbroo@DESKTOP-1F1J3SM ~/Shaders
$ ld shaders.o libcsfml-system.a libcsfml-window.a libcsfml-graphics.a csfml-system-2.dll csfml-window-2.dll csfml-graphics-2.dll
shaders.o:shaders.c:(.text+0x10): undefined reference to `__main'
shaders.o:shaders.c:(.text+0x4bc): undefined reference to `sleep'

MinGW中标准库的名称是什么?如何在LD中链接到标准库?

What is the name of the standard library in MinGW and how do I link to it in LD?

我知道这不能回答问题,但是可以使用以下方法进行编译:

I know this doesnt answer the question, but compiling with this works:

gcc shaders.c libcsfml-system.a libcsfml-window.a libcsfml-graphics.a csfml-system-2.dll csfml-window-2.dll csfml-graphics-2.dll

推荐答案

使用'ld'并不明显.由于 gcc 成功编译了您的项目,您可以通过以下步骤直接使用 'ld' 重现链接阶段.

Using 'ld' in not obvious. Since gcc successfully compiles your project, you can reproduce linking stage directly with 'ld' with the following steps.

  1. 使用添加了-v选项的'gcc'进行编译.这会产生很多文本,您可能希望将其重定向到带有'2> out'
  2. 的文件
  3. 找到以"COLLECT_GCC_OPTIONS ="开头的最后一行
  4. 在此行之后,将会有一个gcc选项列表,用于调节'ld'的行为.从此行中提取以下内容:两个-L选项,它们指向主库文件夹和gcc特定的库文件夹;之后,将使用一系列的对象模块和库.将它们复制到您的"ld"命令行.列表很大.对象和库的顺序很重要!

以下是示例命令行,该命令行成功链接了简单的测试程序:

Here is the sample command line which successfully links simple test program:

ld -Lc:\MinGW\lib\gcc\mingw32\5.3.0 -Lc:\MinGW\lib -o test.exe crt2.o crtbegin.o test.o -lmingw32 -lgcc -lgcc_eh -lmoldname -lmingwex -lmsvcrt -ladvapi32 -lshell32 -luser32 -lkernel32 -lmingw32 -lgcc -lgcc_eh -lmoldname -lmingwex -lmsvcrt crtend.o

您可能需要检查路径,将* .o文件复制到您的文件夹中,或者添加路径并添加您的库.

You may need to check paths, copy *.o files to your folder or add path to them and add your libraries.

这篇关于在MinGW中手动链接标准库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆