链接C代码失败

时间:2015-10-01 20:41:37

标签: c macos compilation linker

我是C编程中的总瘤手。当我运行make:

时,我拿了一些抛出此错误的代码
Undefined symbols for architecture x86_64:
  "_rp_osc_adc_sign", referenced from:
      _rp_osc_meas_min_max in worker.o
      _meas_period in worker.o
  "_rp_osc_meas_cnv_cnt", referenced from:
      _rp_osc_meas_convert in worker.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [make_c_app] Error

我正在使用OS X Yosemite,这是make文件

CC=$(CROSS_COMPILE)gcc
RM=rm

OBJECTS=main.o fpga.o worker.o calib.o fpga_awg.o generate.o fpga_pid.o pid.o

INCLUDE=

#CFLAGS=$(CFLAGS) -Wall -Werror -g
CFLAGS+= -Wall -Werror -g -fPIC $(INCLUDE)
LDFLAGS=-shared


OUT_DIR=../
C_OUT_NAME=$(OUT_DIR)controller.so

all: make_c_app
clean: clean_c_app

make_c_app: $(OBJECTS)
    $(CC) -o $(C_OUT_NAME) $(OBJECTS) $(CFLAGS) $(LDFLAGS)

clean_c_app:
    $(RM) -f $(C_OUT_NAME) $(OBJECTS)

以及链接器抱怨的方法

int rp_osc_meas_min_max(rp_osc_meas_res_t *ch_meas, int sig_data)
{
    int s_data = rp_osc_adc_sign(sig_data);

    if(ch_meas->min > s_data)
        ch_meas->min = s_data;
    if(ch_meas->max < s_data)
        ch_meas->max = s_data;

    ch_meas->avg += s_data;

    return 0;
}

错误可能来自哪里?

编辑:rp_osc_adc_sign按以下方式定义

inline int rp_osc_adc_sign(int in_data)
{
    int s_data = in_data;
    if(s_data & (1<<(c_osc_fpga_adc_bits-1)))
        s_data = -1 * ((s_data ^ ((1<<c_osc_fpga_adc_bits)-1)) + 1);
    return s_data;
}

1 个答案:

答案 0 :(得分:1)

您应该删除在函数

之前编写的inline标记
rp_osc_adc_sign(int in_data)

rp_osc_meas_cnv_cnt