在C

时间:2017-08-24 20:49:51

标签: c gcc

我有一个文件main.c,一个头文件rippledp.h和一个库rippledp.a。问题是:当我执行“make”命令时,我得到了这个输出:

g++ -O2 -DNDEBUG -static   -o rippledp main.o rippledp.a -lm -pthread
main.o: In function `main':
main.c:(.text+0x24): undefined reference to `rippledp_read'
main.c:(.text+0x39): undefined reference to `rippledp'
main.c:(.text+0x43): undefined reference to `rippledp_write'
collect2: ld returned 1 exit status
make: ** [rippledp] Erro 1

这是Makefile:

#--------------------------------------------------#
#  Ripple-DP (ISPD2015 contest version)            #
#  Copyright (c) 2015                              #
#  Department of Computer Science and Engineering  #
#  The Chinese Univeristy of Hong Kong             #
#                                                  #
#  Contact:                                        #
#  Wing-Kai Chow <wkchow@cse.cuhk.edu.hk>          #
#  Evangeline F.Y. Young <fyyoung@cse.cuhk.edu.hk> #
#--------------------------------------------------#

OPT= -O2 -DNDEBUG
#OPT= -O0 -ggdb
TYPE= -static
#WFLAG= -Wall -Winline

CC= g++ $(OPT) $(TYPE) $(WFLAG) $(DEBUG)

LIBS= -lm -pthread

SRCS = ${OBJS:%.o=%.c}
BFILE = rippledp

all:    $(BFILE)

#$(BFILE): main.o rippledp.a libdef.a liblef.a
#   $(CC) -o $(BFILE) main.o rippledp.a libdef.a liblef.a $(LIBS)

$(BFILE): main.o rippledp.a
    $(CC) -o $(BFILE) main.o rippledp.a $(LIBS)

%.o : %.c %.h
    $(CC) -c $*.c


clean:
    rm -f *.o $(BFILE) core

这是main.c:

#include "rippledp.h"

int main(int argc, char **argv){
    /* read benchmark files: tech.lef, cells.lef, floorplan.def */
    /* read global placement solution: placed.def */
    rippledp_read((char*) "tech.lef", (char*) "cells.lef", (char*) "floorplan.def", (char*) "placed.def");

    /* detailed placement with target utility and maximum displacement constraint */
    rippledp(0.8, 200000);

    /* write the detailed placement solution to output file */
    rippledp_write((char*)"dplaced.def");

    return 0;
}

这是rippledp.h:

/*--------------------------------------------------*/
/*  Ripple-DP (ISPD2014 contest version)              */
/*  Copyright (c) 2014                              */
/*  Department of Computer Science and Engineering  */
/*  The Chinese Univeristy of Hong Kong             */
/*                                                  */
/*  Contact:                                        */
/*  Wing-Kai Chow <wkchow@cse.cuhk.edu.hk>          */
/*  Evangeline F.Y. Young <fyyoung@cse.cuhk.edu.hk> */
/*--------------------------------------------------*/

#ifndef _RIPPLEDP_H_
#define _RIPPLEDP_H_

/*read benchmarks and placed global placement solution*/
void rippledp_read(char *tech_file, char *cell_file, char *floorplan_file, char *placed_file);

/*Perform displacement-constrained legalization and detailed placement*/
/* target_util = target utility */
/* max_disp    = maximum displacement constraint */
void rippledp(double target_util, double max_disp);

/*write placement result in DEF format*/
void rippledp_write(char *output_file);

#endif

我还尝试手动编译和链接。我首先编译使用:

gcc -c main.c

然后,我尝试了所有这些替代链接(我将rippledp.a重命名为librippledp.a):

gcc -o out -L. -lrippledp main.o
gcc -o out -L. main.o -lrippledp 
gcc -o out main.o -L. -lrippledp 
gcc main.o -o out -L. -lrippledp 
gcc -o out -lrippledp -L. main.o
gcc -lrippledp -o out -L. main.o

并且输出相同。

我无法访问图书馆内容。

1 个答案:

答案 0 :(得分:4)

Your library是用C ++编译的,因此包含C ++错位名称。但是您将main.c编译为C,因此它查找了未编码的名称,因此无法找到它们。将main.c重命名为main.cpp并使用g ++编译以解决此问题。