我已经安装了zlib-1.2.3.exe。
我在 CLion 2020.1 中有以下设置:
我的CMakeLists.txt
文件中有以下几行:
cmake_minimum_required(VERSION 3.16)
project(ZLIB__test)
set(CMAKE_CXX_STANDARD 11)
set(ZLIB_LIBRARY "C:/Program Files (x86)/GnuWin32")
set(ZLIB_INCLUDE_DIR "C:/Program Files (x86)/GnuWin32/include")
include_directories(${ZLIB_INCLUDE_DIR})
add_executable(ZLIB__test main.cpp)
我在 main.cpp 中有以下源代码:
#include <cstdio>
#include <zlib.h>
// Demonstration of zlib utility functions
unsigned long file_size(char *filename) {
FILE *pFile = fopen(filename, "rb");
fseek(pFile, 0, SEEK_END);
unsigned long size = ftell(pFile);
fclose(pFile);
return size;
}
int decompress_one_file(char *infilename, char *outfilename) {
gzFile infile = gzopen(infilename, "rb");
FILE *outfile = fopen(outfilename, "wb");
if (!infile || !outfile) return -1;
char buffer[128];
int num_read = 0;
while ((num_read = gzread(infile, buffer, sizeof(buffer))) > 0) {
fwrite(buffer, 1, num_read, outfile);
}
gzclose(infile);
fclose(outfile);
}
int compress_one_file(char *infilename, char *outfilename) {
FILE *infile = fopen(infilename, "rb");
gzFile outfile = gzopen(outfilename, "wb");
if (!infile || !outfile) return -1;
char inbuffer[128];
int num_read = 0;
unsigned long total_read = 0, total_wrote = 0;
while ((num_read = fread(inbuffer, 1, sizeof(inbuffer), infile)) > 0) {
total_read += num_read;
gzwrite(outfile, inbuffer, num_read);
}
fclose(infile);
gzclose(outfile);
printf("Read %ld bytes, Wrote %ld bytes,Compression factor %4.2f%%\n",
total_read, file_size(outfilename),
(1.0 - file_size(outfilename) * 1.0 / total_read) * 100.0);
}
int main(int argc, char **argv) {
compress_one_file(argv[1], argv[2]);
decompress_one_file(argv[2], argv[3]);
}
并且,上面的源代码正在生成以下错误:
====================[ Clean | Debug ]===========================================
"C:\Program Files\JetBrains\CLion 2020.1.3\bin\cmake\win\bin\cmake.exe" --build C:\Users\pc\CLionProjects\ZLIB__test\cmake-build-debug --target clean
Clean finished
====================[ Build | all | Debug ]=====================================
"C:\Program Files\JetBrains\CLion 2020.1.3\bin\cmake\win\bin\cmake.exe" --build C:\Users\pc\CLionProjects\ZLIB__test\cmake-build-debug --target all
Scanning dependencies of target ZLIB__test
[ 50%] Building CXX object CMakeFiles/ZLIB__test.dir/main.cpp.obj
In file included from C:\Users\pc\CLionProjects\ZLIB__test\main.cpp:2:
In file included from C:\PROGRA~2\GnuWin32\include\zlib.h:34:
C:\PROGRA~2\GnuWin32\include/zconf.h(289,12): fatal error: 'unistd.h' file not found
# include <unistd.h> /* for SEEK_* and off_t */
^~~~~~~~~~
1 error generated.
NMAKE : fatal error U1077: 'C:\PROGRA~1\LLVM\bin\clang-cl.exe' : return code '0x1'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\bin\HostX64\x64\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\bin\HostX64\x64\nmake.exe"' : return code '0x2'
Stop.
我怎样才能解决这个问题?