cmake产生错误:"'stat64'和#34;的冲突类型

时间:2017-04-24 20:03:39

标签: c cmake

我正在将我的gmake构建转换为cmake构建。使用gmake可以很好地构建应用程序,但是当我使用cmake时,我会得到以下错误。 以下是gmake和cmake文件。

父Makefile

CC      := gcc
CFLAGS  := -g -w -m32
INC_DIR := ../includes
OBJ_DIR := ../objects
BIN_DIR := ../bin

子Makefile

include ../../Makefile

SHR_FX := ../$(OBJ_DIR)/shrfx.o
SHRXML := ../$(OBJ_DIR)/shrxml.o
TMP_BIN_DIR = ../$(BIN_DIR)
TMP_INC_DIR = ../$(INC_DIR)

EXECUTABLES := common flogmon
all: $(EXECUTABLES)

%: %.c OAhelper.c OAhelper.h $(SHR_FX) $(TMP_INC_DIR)
    @-rm -f $@   ## QUIET (@). CONTINUE IF FILE NOT FOUND (-)
    $(CC) $(CFLAGS) -I $(TMP_INC_DIR) $(LDLIBPATHFLAGS) -o $@ $@.c  OAhelper.c $(SHR_FX) 
    @-chmod 0775 $@   #SH(@),CONT(-). Allow others to do it.
    mv $@ $(TMP_BIN_DIR)

parent CMakeList.txt

cmake_minimum_required(VERSION 2.8.9)
project(program)
set(CMAKE_BUILD_TYPE Release)
set (EXECUTABLE_OUTPUT_PATH "/home/user/workspace/program")

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -w -m32")

add_subdirectory(opaid/opaid_helper)

child CMakeList.txt

cmake_minimum_required(VERSION 2.8.9)

#Bring the headers
include_directories(../../includes)

set (PROJ_LIST "common;flogmon")

message ( STATUS "CFLAGS : " ${CMAKE_C_FLAGS})
foreach (PROJ ${PROJ_LIST})
    project(${PROJ})
    SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath=${EXECUTABLE_OUTPUT_PATH}:${EXECUTABLE_OUTPUT_PATH}../RSA/cryptocme3001/library/lib")
    add_executable(${PROJ} ${PROJ}.c OAhelper.c )
    target_link_libraries(${PROJ} LINK_PUBLIC shrfx)
    install(TARGETS ${PROJ} DESTINATION ${EXECUTABLE_OUTPUT_PATH})
endforeach()

错误

Building C object /CMakeFiles/common.dir/common.c.o
In file included from /usr/include/features.h:375:0,
    from /usr/include/sys/poll.h:22,
    from /usr/include/poll.h:1,
    from /home/user/workspace/program/src/common.c:26:
/usr/include/sys/stat.h:503:1: error: conflicting types for ‘stat64’
__NTH (stat64 (const char *__path, struct stat64 *__statbuf))
^
In file included from
/home/user/workspace/program/src/../../includes/fxgen.h:205:0,
    from /home/user/workspace/program/src/../../includes/fx.h:286, 
    from /home/user/workspace/program/src/common.c:39:
/usr/include/sys/stat.h:229:12: note: previous declaration of ‘stat64’
was here extern int stat64 (const char *__restrict __file,

如果我查看/usr/include/sys/stat.h ...

503
# if defined __USE_LARGEFILE64 \
  && (! defined __USE_FILE_OFFSET64 \
      || (defined __REDIRECT_NTH && defined __OPTIMIZE__))
__extern_inline int
__NTH (stat64 (const char *__path, struct stat64 *__statbuf))
{
  return __xstat64 (_STAT_VER, __path, __statbuf);
}

229
#ifdef __USE_LARGEFILE64
extern int stat64 (const char *__restrict __file,
           struct stat64 *__restrict __buf) __THROW __nonnull ((1, 2));
extern int fstat64 (int __fd, struct stat64 *__buf) __THROW __nonnull ((2));
#endif

1 个答案:

答案 0 :(得分:0)

将此添加到我的CMAKEList.txt解决了问题:

STRING(REPLACE" -O3"" -O0" CMAKE_C_FLAGS_RELEASE $ {CMAKE_C_FLAGS_RELEASE})