将 libpng 与 Borland C++ 链接
我使用 OpenGL 在 Mac OS X 上制作了一个程序并动态链接 libpng。我现在正在尝试将其移植到Windows。每当我尝试在 Borland 中编译和链接我的移植程序时,都会出现此错误以及大约 10 个相同的错误,但具有不同的“_png_create_read_struct”:
错误:无法解析来自 C:\PROGRAMMING\PNGTEST.OBJ 的外部“_png_create_read_struct”引用
我认为这是因为我没有使用 Borland C++ 5.5.1 为 Win32。我已将 png.h 和 pngconf.h 放入包含文件夹中 C:\Borland\BCC55\Ininclude,并且已放入 libpng12.dll.a、libpng13.a、libpng13.dll.a、libpng.a、libpng .dll.a、libpng12.def、libpng.def、libpng12.la 和 libpng.la 放入 C:\Borland\BCC55\Lib (可能不需要全部,但作为菜鸟,我不知道哪些)需要和不需要)。
我还需要将 libpng.obj 文件放在那里吗?如果是这样,我该如何制作/获得一个?我尝试使用 makefile.bc32 来设置 libpng,但这给了我一个缺少分隔符的错误。
以下是我的命令行选项:
bcc32 -tW pngtest.cpp -lpng
我在代码中包含 png.h。我做错了什么,或者有没有更好的方法来加载不需要 libpng 的 alpha 图像,甚至有更好的编译器来获取 Windows?
I made a program on Mac OS X using OpenGL and dynamically linking libpng. I'm now trying to port it to Windows. Whenever I try to compile and link my ported program in Borland it gives me this error and about 10 more that are the same, but with a different '_png_create_read_struct':
Error: Unresolved external '_png_create_read_struct' reference from C:\PROGRAMMING\PNGTEST.OBJ
I assume it's because I have not properly set up libpng with Borland C++ 5.5.1 for Win32. I've put png.h and pngconf.h into the include folder into C:\Borland\BCC55\Include, and I have put libpng12.dll.a, libpng13.a, libpng13.dll.a, libpng.a, libpng.dll.a, libpng12.def, libpng.def, libpng12.la, and libpng.la into C:\Borland\BCC55\Lib (there is probably no need for them all, but as a noob I have no idea which ones are needed and not).
Do I need to put a libpng.obj file in there too? And if so how would I make/get one? I have tried using makefile.bc32 to set up libpng, yet that gives me a missing separator error.
Here are my command-line options:
bcc32 -tW pngtest.cpp -lpng
I include png.h in my code. What am I doing wrong or is there an even better way to load images with alpha that doesn't need libpng, or even a better compiler to get for Windows?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用 MinGW 编译器可能比使用 Borland 更好。 Borland 不再得到很好的支持。
您还可以下载 DevC++ 并查看其插件机制中是否有 libpng 包。
DevC++ 是一个使用 MinGW C/C++ 编译器的 IDE。
也就是说,如果您觉得必须使用密件抄送,那么您要么必须
a) 使用 Borland 构建 libpng。如果您要使用 borland,这是最好的解决方案。
b) 我认为使用 Impdef 从 libpng.dll 创建导入库。您将在 borland bin 目录中找到 impdef.exe 或 imp(something).exe。
请注意,某些库无法与 impdef 一起使用,因为存在链接到 dll 的静态代码,导致它在没有正确运行时的情况下失败。
You're probably better off with the MinGW compiler than Borland. Borland is not well supported any longer.
You could also download DevC++ and see if it has a libpng package in its addon mechanism.
DevC++ is an IDE that uses the MinGW C/C++ compiler.
That said, if you feel you must use BCC, you'll either have to
a) Build libpng with Borland. This is the best solution if you're going to use borland.
b) Use, I think, Impdef to create an import library from libpng.dll. You'll find impdef.exe or imp(something).exe in the borland bin directory.
Note that some libraries will not work with impdef as there is static code linked to the dll that causes it to fail without the proper runtime.
首先,我不会用第三方库“污染”BC55 安装;它将使得将项目转移到其他构建环境变得更加困难。最好将它们放在项目中的文件夹中。
其次,您知道您尝试链接的导出库是为 BC55 构建的吗? .a 扩展名建议使用 GNU 库(Borland 库通常使用 .lib 扩展名),在这种情况下,它不会与使用不同目标文件格式的 BC55 链接。如果是这种情况,您将需要按照您尝试的方式重建库,因此我建议您确实应该问一个有关这样做时遇到的问题的问题。我想知道 makefile 是为 Borland make 还是 GNU make 编写的,因为它们具有不同的语法?
命令行选项
-lpng
对于 GCC 可能是正确的(它将链接 libpng.a),但对于 BCC 来说毫无意义。-l
选项仅将后面的文本传递给链接器。 链接器命令行要求传递完整名称,并且如果未提供扩展名,.lib 是隐式添加的。First of all, I would not have "polluted" the BC55 installation with third-party libraries; it will make moving the project to other build environments much more difficult. It would have been better to place them in a folder within your project.
Secondly do you know that the export library you are attempting to link is built for BC55? The .a extension suggests a GNU library (Borland libraries conventionally use .lib extension), in which case it would not link with BC55 which uses a different object file format. If this is the case you will need to rebuild the library as you attempted to do, so I suggest that you should really be asking a question about the problem you had with doing just that. I wonder whether the makefile is written for Borland make or GNU make, since they have differing syntax?
The command line option
-lpng
might be correct for GCC (where it will link libpng.a), but is meaningless to BCC. The-l
option merely passes the text that follows to the linker. The linker command line, requires that the complete name be passed, and if no extension is provided, .lib is added implicitly.您可能应该使用 coff2omf 来转换库。 DLL 文件几乎肯定采用“Microsoft”COFF 格式。
请参阅COFF2OMF.EXE,导入库转换工具。
You should probably just use coff2omf to convert the library. The DLL files are almost certainly in "Microsoft" COFF format.
See COFF2OMF.EXE, the Import Library Conversion Tool.