将miniz.c添加到项目中并包含它:
#include "miniz.c"
int main(){
return 0;
}
链接器会发出大量“已定义”的错误。
1> miniz.c
1> Source.cpp
1>Source.obj : error LNK2005: _mz_zip_extract_archive_file_to_heap already defined in miniz.obj
1>Source.obj : error LNK2005: _mz_zip_add_mem_to_archive_file_in_place already defined in miniz.obj
1>Source.obj : error LNK2005: _mz_zip_writer_end already defined in miniz.obj
1>Source.obj : error LNK2005: _mz_zip_writer_finalize_heap_archive already defined in miniz.obj
1>Source.obj : error LNK2005: _mz_zip_writer_finalize_archive already defined in miniz.obj
1>Source.obj : error LNK2005: _mz_zip_writer_add_from_zip_reader already defined in miniz.obj
1>Source.obj : error LNK2005: _mz_zip_writer_add_file already defined in miniz.obj
1>Source.obj : error LNK2005: _mz_zip_writer_add_mem_ex already defined in miniz.obj
1>Source.obj : error LNK2005: _mz_zip_writer_add_mem already defined in miniz.obj
1>Source.obj : error LNK2005: _mz_zip_writer_init_from_reader already defined in miniz.obj
1>Source.obj : error LNK2005: _mz_zip_writer_init_file already defined in miniz.obj
1>Source.obj : error LNK2005: _mz_zip_writer_init_heap already defined in miniz.obj
1>Source.obj : error LNK2005: _mz_zip_writer_init already defined in miniz.obj
1>Source.obj : error LNK2005: _mz_zip_reader_extract_file_to_file already defined in miniz.obj
1>Source.obj : error LNK2005: _mz_zip_reader_end already defined in miniz.obj
1>Source.obj : error LNK2005: _mz_zip_reader_extract_to_file already defined in miniz.obj
1>Source.obj : error LNK2005: _mz_zip_reader_extract_file_to_callback already defined in miniz.obj
1>Source.obj : error LNK2005: _mz_zip_reader_extract_to_callback already defined in miniz.obj
1>Source.obj : error LNK2005: _mz_zip_reader_extract_file_to_heap already defined in miniz.obj
1>Source.obj : error LNK2005: _mz_zip_reader_extract_to_heap already defined in miniz.obj
1>Source.obj : error LNK2005: _mz_zip_reader_extract_file_to_mem already defined in miniz.obj
1>Source.obj : error LNK2005: _mz_zip_reader_extract_to_mem already defined in miniz.obj
1>Source.obj : error LNK2005: _mz_zip_reader_extract_file_to_mem_no_alloc already defined in miniz.obj
1>Source.obj : error LNK2005: _mz_zip_reader_extract_to_mem_no_alloc already defined in miniz.obj
1>Source.obj : error LNK2005: _mz_zip_reader_locate_file already defined in miniz.obj
1>Source.obj : error LNK2005: _mz_zip_reader_get_filename already defined in miniz.obj
1>Source.obj : error LNK2005: _mz_zip_reader_file_stat already defined in miniz.obj
1>Source.obj : error LNK2005: _mz_zip_reader_is_file_a_directory already defined in miniz.obj
1>Source.obj : error LNK2005: _mz_zip_reader_is_file_encrypted already defined in miniz.obj
1>Source.obj : error LNK2005: _mz_zip_reader_get_num_files already defined in miniz.obj
1>Source.obj : error LNK2005: _mz_zip_reader_init_file already defined in miniz.obj
1>Source.obj : error LNK2005: _mz_zip_reader_init_mem already defined in miniz.obj
1>Source.obj : error LNK2005: _mz_zip_reader_init already defined in miniz.obj
1>Source.obj : error LNK2005: _tdefl_write_image_to_png_file_in_memory already defined in miniz.obj
1>Source.obj : error LNK2005: _tdefl_write_image_to_png_file_in_memory_ex already defined in miniz.obj
1>Source.obj : error LNK2005: _tdefl_create_comp_flags_from_zip_params already defined in miniz.obj
1>Source.obj : error LNK2005: _tdefl_compress_mem_to_mem already defined in miniz.obj
1>Source.obj : error LNK2005: _tdefl_compress_mem_to_heap already defined in miniz.obj
1>Source.obj : error LNK2005: _tdefl_compress_mem_to_output already defined in miniz.obj
1>Source.obj : error LNK2005: _tdefl_get_adler32 already defined in miniz.obj
1>Source.obj : error LNK2005: _tdefl_get_prev_return_status already defined in miniz.obj
1>Source.obj : error LNK2005: _tdefl_init already defined in miniz.obj
1>Source.obj : error LNK2005: _tdefl_compress_buffer already defined in miniz.obj
1>Source.obj : error LNK2005: _tdefl_compress already defined in miniz.obj
1>Source.obj : error LNK2005: _tinfl_decompress_mem_to_callback already defined in miniz.obj
1>Source.obj : error LNK2005: _tinfl_decompress_mem_to_mem already defined in miniz.obj
1>Source.obj : error LNK2005: _tinfl_decompress_mem_to_heap already defined in miniz.obj
1>Source.obj : error LNK2005: _tinfl_decompress already defined in miniz.obj
1>Source.obj : error LNK2005: _mz_error already defined in miniz.obj
1>Source.obj : error LNK2005: _mz_uncompress already defined in miniz.obj
1>Source.obj : error LNK2005: _mz_inflateEnd already defined in miniz.obj
1>Source.obj : error LNK2005: _mz_inflate already defined in miniz.obj
1>Source.obj : error LNK2005: _mz_inflateInit already defined in miniz.obj
1>Source.obj : error LNK2005: _mz_inflateInit2 already defined in miniz.obj
1>Source.obj : error LNK2005: _mz_compressBound already defined in miniz.obj
1>Source.obj : error LNK2005: _mz_compress already defined in miniz.obj
1>Source.obj : error LNK2005: _mz_compress2 already defined in miniz.obj
1>Source.obj : error LNK2005: _mz_deflateBound already defined in miniz.obj
1>Source.obj : error LNK2005: _mz_deflateEnd already defined in miniz.obj
1>Source.obj : error LNK2005: _mz_deflate already defined in miniz.obj
1>Source.obj : error LNK2005: _mz_deflateReset already defined in miniz.obj
1>Source.obj : error LNK2005: _mz_deflateInit2 already defined in miniz.obj
1>Source.obj : error LNK2005: _mz_deflateInit already defined in miniz.obj
1>Source.obj : error LNK2005: _mz_version already defined in miniz.obj
1>Source.obj : error LNK2005: _mz_free already defined in miniz.obj
1>Source.obj : error LNK2005: _mz_crc32 already defined in miniz.obj
1>Source.obj : error LNK2005: _mz_adler32 already defined in miniz.obj
为那些不熟悉图书馆https://code.google.com/p/miniz/
的人链接到miniz.c答案 0 :(得分:8)
永远不会包含源文件!他们不打算这样做。
头文件.h
中的单独声明和.c
文件中的定义。
将头文件包含在需要引用声明的任何位置。
至于您的具体情况,您应该包含miniz.c
,如下所示
#define MINIZ_HEADER_FILE_ONLY
#include "miniz.c"
int main(){
return 0;
}
这在miniz.c
文件本身(第928行)
// ------------------- End of Header: Implementation follows.
// (If you only want the header, define MINIZ_HEADER_FILE_ONLY.)
答案 1 :(得分:2)
为了使用这个疯狂设计的库作为作者(显然)的意图,你需要:
或者,您可以编写自己的包含库声明的标头,包括而不是.c
文件,并将库编译并链接为普通源文件。或者您可以查找由了解编译模型的人编写的库。