【问题标题】:cmake produces error: "conflicting types for ‘stat64’"cmake 产生错误:“'stat64' 的类型冲突”
【发布时间】:2017-04-24 20:03:39
【问题描述】:

我正在将我的 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)

父 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)

子 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

【问题讨论】:

  • 运行 make VERBOSE=1 并检查 gmake 调用中命令行之间的差异。
  • 看起来您好像遗漏了最后一个错误行的最后一部分。然而,这可能不是一个大问题——它可能是struct stat64 *__statbuf); 或其他类似的东西丢失了。您可能必须追踪common.cfx.hfxgen.h 标头正在做什么以使stat64() 的两个不兼容声明可见。问题可能出在common.c 之前包含的另一个标题中,但我将从这些开始。 (使用gcc -H 列出所有包含的文件,因为它们也包含在内 - 它也可能有帮助。)
  • 请注意,CMake 不是 [g]make 的模拟;它更符合 Autotools 的路线。事实上,CMake 为您生成的 makefile 很有可能会在处理旧 makefile 的所有平台上由 gmake (== GNU make) 处理。
  • 无论如何,在分析构建命令的差异时,请特别注意命令行宏定义的差异。还要在common.c 的第 26 行和第 39 行之间查找(可能是有条件的)宏定义。总的来说,所有可能影响头文件解释的宏定义都应该在任何头包含之前进行。
  • 感谢您的建议,使用 VERBOSE=1: cmake 有 -03 -DNDEBUG 而 gmake 没有。如何摆脱 cmake 中的那些编译器标志?

标签: c cmake


【解决方案1】:

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

字符串(替换“-O3”“-O0”CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE})

【讨论】:

    猜你喜欢
    • 2016-02-07
    • 2013-03-25
    • 1970-01-01
    • 1970-01-01
    • 2014-03-10
    • 2012-10-04
    • 2013-04-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多