简体   繁体   English

将libpng与Borland C ++链接

[英]Linking libpng with Borland C++

I made a program on Mac OS X using OpenGL and dynamically linking libpng . 我使用OpenGL并动态链接libpng在Mac OS X上编写了一个程序。 I'm now trying to port it to Windows. 我现在正尝试将其移植到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': 每当我尝试在Borland上编译并链接我的移植程序时,都会出现此错误,并且会发出大约10个相同的错误,但带有不同的'_png_create_read_struct':

Error: Unresolved external '_png_create_read_struct' reference from C:\\PROGRAMMING\\PNGTEST.OBJ 错误:来自C:\\ PROGRAMMING \\ PNGTEST.OBJ的未解析的外部'_png_create_read_struct'引用

I assume it's because I have not properly set up libpng with Borland C++ 5.5.1 for Win32 . 我认为这是因为我没有使用Borland C ++ 5.5.1为Win32正确设置libpng。 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). 我已将png.h和pngconf.h放入include文件夹中的C:\\ Borland \\ BCC55 \\ Include中,并将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(可能不需要它们,但是作为菜鸟,我不知道哪一个是必需的,而不是)。

Do I need to put a libpng.obj file in there too? 我也需要在其中放置一个libpng.obj文件吗? 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. 我尝试使用makefile.bc32设置libpng,但是这给了我一个缺少的分隔符错误。

Here are my command-line options: 这是我的命令行选项:

bcc32 -tW pngtest.cpp -lpng

I include png.h in my code. 我在代码中包含png.h。 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? 我做错了什么,还是有更好的方法来加载不需要libpng的alpha图像,甚至没有更好的Windows编译器?

You're probably better off with the MinGW compiler than Borland. 使用MinGW编译器可能比Borland更好。 Borland is not well supported any longer. Borland不再得到很好的支持。

You could also download DevC++ and see if it has a libpng package in its addon mechanism. 您还可以下载DevC ++,并查看其插件机制中是否包含libpng软件包。 DevC++ is an IDE that uses the MinGW C/C++ compiler. DevC ++是使用MinGW C / C ++编译器的IDE。

That said, if you feel you must use BCC, you'll either have to a) Build libpng with Borland. 就是说,如果您觉得必须使用BCC,则必须要么a)使用Borland构建libpng。 This is the best solution if you're going to use borland. 如果您要使用borland,这是最好的解决方案。 b) Use, I think, Impdef to create an import library from libpng.dll. b)我认为可以使用Impdef从libpng.dll创建一个导入库。 You'll find impdef.exe or imp(something).exe in the borland bin directory. 您会在borland bin目录中找到impdef.exe或imp(something).exe。 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. 请注意,某些库无法与impdef一起使用,因为存在链接到dll的静态代码,导致该代码在没有适当的运行时失败。

First of all, I would not have " polluted " the BC55 installation with third-party libraries; 首先,我不会用第三方库“ 污染 ” BC55安装; 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? 其次,您知道您尝试链接的导出库是为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. .a扩展名建议使用GNU库(Borland库通常使用.lib扩展名),在这种情况下,它不会与使用其他目标文件格式的BC55链接。 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? 我想知道makefile是为Borland make还是GNU make编写的,因为它们的语法不同?

The command line option -lpng might be correct for GCC (where it will link libpng.a), but is meaningless to BCC. 命令行选项-lpng对于GCC可能是正确的(它将链接libpng.a),但对BCC没有意义。 The -l option merely passes the text that follows to the linker. -l 选项仅将后面的文本传递给链接器。 The linker command line , requires that the complete name be passed, and if no extension is provided, .lib is added implicitly. 链接器命令行 ,要求传递完整名称,如果未提供扩展名,则隐式添加.lib。

You should probably just use coff2omf to convert the library. 您可能应该只使用coff2omf来转换库。 The DLL files are almost certainly in "Microsoft" COFF format. DLL文件几乎可以肯定是“ Microsoft” COFF格式。

See COFF2OMF.EXE, the Import Library Conversion Tool . 请参阅导入库转换工具COFF2OMF.EXE

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM