本人使用我们经理写的一个库,但是总报multiple definition of错误,求教高手解答.
我简单写了个测试程序:一个头文件header,一个main文件.
header中的头文件和main中的变量类型都是库libxbase.a中定义的,这个库在windows下使用没有问题,但是linux下就报错误,不知道是不是我的makefile写错了,请高手指点.
1.header.h
#ifndef __HEADER_H__
#define __HEADER_H__
#include "stx_base_type.h"
#include "stx_io.h"
#include "stx_io_tcp.h"
#endif
2.main.cpp
#include "header.h"
int main()
{
stx_xio* srvSock = 0;
srvSock = stx_create_io_tcp();
return 0;
}
3.Makefile
TARGET = FC3
CFLAGS = -g
#LDFLAGS = -lm -pthread
LIBS = -L../xbase/xbase -lxbase
INCLUDES = -I.
INCLUDES += -I../xbase/include
INCLUDES += -I../xbase/xbase
CC = gcc
SRC = main.cpp
OBJ = $(SRC:.cpp=.o)
all:$(TARGET)
$(TARGET):$(OBJ)
$(CC) -o $@ $< $(LIBS)
%.o:%.cpp
$(CC) -o $@ -c $< $(CFLAGS) $(INCLUDES)
clean:
rm -rf $(TARGET)
rm -rf $(OBJ)
4.错误信息
gcc -o main.o -c main.cpp -g -I. -I../xbase/include -I../xbase/xbase
gcc -o FC3 main.o -L../xbase/xbase -lxbase
../xbase/xbase/libxbase.a(stx_mem.o)(.text+0x0): In function `GetWidthFromRatio':
../include/stx_base_type.h:1069: multiple definition of `GetWidthFromRatio'
../xbase/xbase/libxbase.a(stx_io_tcp.o)(.text+0x0):../include/stx_base_type.h:1069: first defined here
../xbase/xbase/libxbase.a(stx_mem.o)(.text+0x14): In function `GetHeightFromRatio':
../include/stx_base_type.h:1073: multiple definition of `GetHeightFromRatio'
../xbase/xbase/libxbase.a(stx_io_tcp.o)(.text+0x14):../include/stx_base_type.h:1073: first defined here
../xbase/xbase/libxbase.a(stx_mem.o)(.text+0x24): In function `av_log2':
../include/stx_mem.h:56: multiple definition of `av_log2'
../xbase/xbase/libxbase.a(stx_io_tcp.o)(.text+0x1678):../include/stx_mem.h:56: first defined here
../xbase/xbase/libxbase.a(stx_sock_err.o)(.text+0x0): In function `GetWidthFromRatio':
../include/stx_base_type.h:1069: multiple definition of `GetWidthFromRatio'
于 2012-02-09 11:08:21发表:
应该是stx_base_type.h 文件里做了函数或变量的定义导致, 改为声明,将定义在*.cpp 或*.c文件实现,试一试
fanglk8899 于 2009-06-16 16:54:45发表:
坐沙发
fanglk8899 于 2009-06-16 16:54:44发表:
坐沙发