Clion中的多定义错误
我在ClionClion中的多定义错误,c,compiler-errors,c-preprocessor,C,Compiler Errors,C Preprocessor,我在ClionC项目中添加了“”(一个头文件和一个源文件),但我无法构建该项目。 错误是: multiple definition of `mts_lrand' 我可以使用命令行和gcc成功编译和运行程序,但在Clion中我不能 我认为这与宏有关,但我不知道如何修复它 下面是我添加的部分代码: mtwist.h . . . . /* * In gcc, inline functions must be declared extern or they'll produce * assembl
C
项目中添加了“”(一个头文件和一个源文件),但我无法构建该项目。
错误是:
multiple definition of `mts_lrand'
我可以使用命令行和gcc成功编译和运行程序,但在Clion中我不能
我认为这与宏有关,但我不知道如何修复它
下面是我添加的部分代码:
mtwist.h
.
.
.
.
/*
* In gcc, inline functions must be declared extern or they'll produce
* assembly code (and thus linking errors). We have to work around
* that difficulty with the MT_EXTERN define.
*/
#ifndef MT_EXTERN
#ifdef __cplusplus
#define MT_EXTERN /* C++ doesn't need static */
#else /* __cplusplus */
#define MT_EXTERN extern /* C (at least gcc) needs extern */
#endif /* __cplusplus */
#endif /* MT_EXTERN */
/*
* Make it possible for mtwist.c to disable the inline keyword. We
* use our own keyword so that we don't interfere with inlining in
* C/C++ header files, above.
*/
#ifndef MT_INLINE
#define MT_INLINE inline /* Compiler has inlining */
#endif /* MT_INLINE */
/*
* Try to guess whether the compiler is one (like gcc) that requires
* inline code to be available in the header file, or a smarter one
* that gets inlines directly from object files. But if we've been
* given the information, trust it.
*/
#ifndef MT_GENERATE_CODE_IN_HEADER
#ifdef __GNUC__
#define MT_GENERATE_CODE_IN_HEADER 1
#endif /* __GNUC__ */
#if defined(__INTEL_COMPILER) || defined(_MSC_VER)
#define MT_GENERATE_CODE_IN_HEADER 0
#endif /* __INTEL_COMPILER || _MSC_VER */
#endif /* MT_GENERATE_CODE_IN_HEADER */
#if MT_GENERATE_CODE_IN_HEADER
/*
* Generate a random number in the range 0 to 2^32-1, inclusive, working
* from a given state vector.
*
* The generator is optimized for speed. The primary optimization is that
* the pseudorandom numbers are generated in batches of MT_STATE_SIZE. This
* saves the cost of a modulus operation in the critical path.
*/
MT_EXTERN MT_INLINE uint32_t mts_lrand(
register mt_state* state) /* State for the PRNG */
{
register uint32_t random_value; /* Pseudorandom value generated */
if (state->stateptr <= 0)
mts_refresh(state);
random_value = state->statevec[--state->stateptr];
MT_PRE_TEMPER(random_value);
return MT_FINAL_TEMPER(random_value);
}
.
.
.
.
。
.
.
.
/*
*在gcc中,内联函数必须声明为extern,否则它们将生成
*汇编代码(从而链接错误)。我们必须四处工作
*这是外星人定义的困难。
*/
#伊夫德夫山外部酒店
#ifdef_uucplusplus
定义MTXEXNE/*C++不需要静态*/
#else/*\uuuCPlusplus*/
#定义MT_EXTERN EXTERN/*C(至少gcc)需要EXTERN*/
#endif/*\uuu cplusplus*/
#endif/*MT_EXTERN*/
/*
*使mtwist.c能够禁用内联关键字。我们
*使用我们自己的关键字,这样我们就不会干扰
*上面的C/C++头文件。
*/
#ifndef MT_内联
#定义MT_INLINE/*编译器具有内联*/
#endif/*MT_内联*/
/*
*尝试猜测编译器是否是需要
*内联代码可以在头文件中使用,也可以在更智能的头文件中使用
*直接从对象文件获取内联线的。但是如果我们
*有了这些信息,相信它。
*/
#ifndef MT_在\u头中生成\u代码\u
#ifdef__GNUC__
#在\u头1中定义MT\u生成\u代码\u
#endif/*\uuuu GNUC\uu*/
#如果已定义(u英特尔编译器)|已定义(_MSC_版本)
#在\u头0中定义MT\u生成\u代码\u
#endif/*__英特尔编译器| | | MSC版本*/
#endif/*MT\u生成\u头中的\u代码*/
#如果MT\u在\u头中生成\u代码\u
/*
*生成范围为0到2^32-1(含)的随机数,有效
*从给定的状态向量。
*
*发电机的速度得到了优化。主要的优化是
*伪随机数以MT_STATE_大小批量生成。这
*节省关键路径中模运算的成本。
*/
机器外部机器内联装置32机器外联装置(
注册PRNG的mt_状态*状态)/*状态*/
{
寄存器uint32\u t随机值;/*生成伪随机值*/
if(state->stateptr statevec[--state->stateptr];
MT_预_回火(随机值);
返回MT\U最终状态(随机值);
}
.
.
.
.
你看函数定义在头文件中,我想这就是问题所在,但我不知道该怎么办
您可以看到完整的代码。我解决了一个类似的错误,将
\define MT\u NO\u INLINE
放在\include
之前。