C++编程-6:undefined reference to 'XXXX'问题汇总

一、标准C库中的函数未定义

编译报错:

undefined reference to `__isoc99_sscanf'
undefined reference to `__isoc99_fscanf'
undefined reference to `__pow_finite'
undefined reference to `__powf_finite'
undefined reference to `__ctype_toupper_loc'
undefined reference to `__log10_finite'
undefined reference to `sklsip_clean'
undefined reference to `__fxstat64'
undefined reference to `__assert_fail'
undefined reference to `__log2f_finite'
undefined reference to `__xstat64'
undefined reference to `__ctype_b_loc'
undefined reference to `_IO_getc'
undefined reference to `__ctype_tolower_loc'
undefined reference to `__xstat'
undefined reference to `_IO_putc'
undefined reference to `__strdup'
undefined reference to `__rawmemchr'
undefined reference to `shm_open'
undefined reference to `__log_finite'
undefined reference to `__strtok_r'
undefined reference to `__fxstat'
undefined reference to `shm_unlink'
undefined reference to `__log2_finite'
undefined reference to `__exp_finite'

问题分析:编译链不对。

问题解决:更换编译链。

二、原子库中函数未定义

编译报错:

undefined reference to `__sync_fetch_and_sub_8'
undefined reference to `__sync_fetch_and_add_8'
undefined reference to `__sync_val_compare_and_swap_8'
undefined reference to `__atomic_store_8'
undefined reference to `__atomic_fetch_add_8'

问题分析:编译链中缺少原子函数的实现。

问题解决:将libatomic.c和libatomic_config.h使用对应编译链编译成库,再将libatomic.cpp和编译好的库链接到源码中。

//libatomic.c
/* Basic implementation of libatomic for GCC.
   This basic implementation currently assumes everything is aligned. 

   Copyright (C) 2010, 2011
   Free Software Foundation, Inc.

   This file is part of GCC.

   GCC is free software; you can redistribute it and/or modify it
   under the terms of the GNU General Public License as published by the
   Free Software Foundation; either version 3, or (at your option) any
   later version.

   GCC is distributed in the hope that it will be useful, but WITHOUT
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   for more details.

   You should have received a copy of the GNU General Public License
   along with GCC; see the file COPYING3.  If not see
   <http://www.gnu.org/licenses/>.  */


#include <stdbool.h>
#include <string.h>
#include <stdint.h>
#include <stddef.h>

/* These defines should be defined based on configuration of what the target
   supports.  Changing these #defines is all that is required to use this
   file.  If your target supports unsigned int type of the appropriate
   number of bytes, simply define it as 1.  Note that for I16 you may 
   also have to change the type from __int128_t to int128_t if approriate.  

   Also note that you can expect to see warning from compiler similar to :
warning: conflicting types for built-in function ‘__atomic_compare_exchange_1’
   This is expected behaviour.  */

#include <libatomic_config.h>

#ifndef  __LIBATOMIC_SUPPORTS_I1
#define __LIBATOMIC_SUPPORTS_I1		1
#endif

#ifndef  __LIBATOMIC_SUPPORTS_I2
#define __LIBATOMIC_SUPPORTS_I2		1
#endif

#ifndef  __LIBATOMIC_SUPPORTS_I4
#define __LIBATOMIC_SUPPORTS_I4		1
#endif

#ifndef  __LIBATOMIC_SUPPORTS_I8
#define __LIBATOMIC_SUPPORTS_I8		1
#endif

#ifndef  __LIBATOMIC_SUPPORTS_I1
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值