c - 无法运行 LodePNG 示例

标签 c

根据README file at the Github repository for LodePNG :

Only two files are needed to allow your program to read and write PNG files: lodepng.cpp and lodepng.h. The other files in the project are just examples, unit tests, etc...

我将lodepng.hlodepng.cppexample_encode.c保存到我的工作文件夹,重命名为lodepng.cpp 按照指示添加到 lodepng.c,并尝试运行 example_encode.c。迎接我的是大量的错误:

C:\Users\Peter\AppData\Local\Temp\ccqdyxic.o:example_encode.c:(.text+0x30): undefined reference to `lodepng_encode32_file'
C:\Users\Peter\AppData\Local\Temp\ccqdyxic.o:example_encode.c:(.text+0x43): undefined reference to `lodepng_error_text'
C:\Users\Peter\AppData\Local\Temp\ccqdyxic.o:example_encode.c:(.text+0x98): undefined reference to `lodepng_encode32'
C:\Users\Peter\AppData\Local\Temp\ccqdyxic.o:example_encode.c:(.text+0xb5): undefined reference to `lodepng_save_file'
C:\Users\Peter\AppData\Local\Temp\ccqdyxic.o:example_encode.c:(.text+0xc5): undefined reference to `lodepng_error_text'
C:\Users\Peter\AppData\Local\Temp\ccqdyxic.o:example_encode.c:(.text+0x127): undefined reference to `lodepng_state_init'
C:\Users\Peter\AppData\Local\Temp\ccqdyxic.o:example_encode.c:(.text+0x15e): undefined reference to `lodepng_encode'
C:\Users\Peter\AppData\Local\Temp\ccqdyxic.o:example_encode.c:(.text+0x18a): undefined reference to `lodepng_save_file'
C:\Users\Peter\AppData\Local\Temp\ccqdyxic.o:example_encode.c:(.text+0x1a0): undefined reference to `lodepng_error_text'
C:\Users\Peter\AppData\Local\Temp\ccqdyxic.o:example_encode.c:(.text+0x1c6): undefined reference to `lodepng_state_cleanup'

所有的错误都引用了已经在 lodepng.h 中定义的函数,它是使用 #include "lodepng.h"example_encode.c 文件在 Github 链接中给出,所以我不明白为什么会出现这个问题。

有没有人遇到过这个问题?

最佳答案

听起来您需要将 lodepng.c 与示例程序链接起来,如下所示:

$ gcc -o example_encode lodepng.c example_encode.c

关于c - 无法运行 LodePNG 示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25476923/

相关文章:

c++ - 浮点错误 -1.#J 是什么意思?

Codeblocks GTK 项目未找到 gtk.h 并且此路径不包含 include 或 lib 文件夹

c - fwrite() 之后的 fread() 获取 0 个字节

c - 使用 openat 重新打开一个目录

c - 解析c中不带空格的命令行参数

c - 访问结构中结构的成员

android - CMake 链接静态库错误,而 NDK 工作正常

c - fgets 被传递

c - 函数指针,如何转换?

c - 为什么这个指针操作不起作用?