问题描述
在将miniz.c添加到项目中并包含它之后:
After adding miniz.c to the project and including it:
#include "miniz.c"
int main(){
return 0;
}
链接器发出大量的已定义错误。 p>
The linker spits out a huge amount of "already defined" errors.
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
链接到不熟悉库的人的miniz.c
Link to miniz.c for those who are not familiar with the library https://code.google.com/p/miniz/
推荐答案
永远不要包含源文件!他们不打算这样做。
Never, ever include source files! They aren't intended to do so.
在头文件 .h
中单独声明并在 .c
文件。
Separate declarations in a header file .h
and definitions in the .c
file.
将头文件包含在需要引用声明的任何位置。
Include the header file anywhere you need to refer to the declarations.
对于你的特殊情况,你应该包括 miniz.c
如下
As for your particular case you should have included the miniz.c
as follows
#define MINIZ_HEADER_FILE_ONLY
#include "miniz.c"
int main(){
return 0;
}
这在 miniz.c
文件本身(在第928行)
This is documented in the miniz.c
file itself (at line 928)
// ------------------- End of Header: Implementation follows.
// (If you only want the header, define MINIZ_HEADER_FILE_ONLY.)
这篇关于miniz.c获取“已定义” VS中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!