关于在 ubuntu 上链接 zlib 中的错误

Moo*_*ehe 2 c c++ ubuntu zlib

最近我需要在 Ubuntu 上使用 zlib 进行编程,这里我遇到了问题。我写了一个小程序来测试 zlib 函数,并在 Eclipse 中构建它。我发现它可以编译,但有一些像这样的链接错误:

main.cpp:27: undefined reference to `compress'
main.cpp:38: undefined reference to `uncompress'
Run Code Online (Sandbox Code Playgroud)

我该怎么办?如果这是因为没有库文件?

任何人都可以提供一些帮助吗?非常感谢!

MOODY_Y

另外,这是我的建筑信息:

11:59:08 **** Build of configuration Debug for project test_zlib ****
make all 
Building file: ../main.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"main.d" -MT"main.d" -o "main.o" "../main.cpp"
Finished building: ../main.cpp

Building target: test_zlib
Invoking: GCC C++ Linker
g++  -o "test_zlib"  ./main.o   
./main.o: In function `main':
/home/hyq/workspace/test_zlib/Debug/../main.cpp:27: undefined reference to `compress'
/home/hyq/workspace/test_zlib/Debug/../main.cpp:38: undefined reference to `uncompress'
collect2: ld return 1
make: *** [test_zlib] error 1

11:59:10 Build Finished (took 1s.715ms)
Run Code Online (Sandbox Code Playgroud)

Mar*_*ler 5

尝试:

sudo apt-get install zlib1g-dev
Run Code Online (Sandbox Code Playgroud)

另外,-lz在编译/链接命令上使用。