尝试使用 cmake 编译程序时出现问题

问题描述 投票:0回答:1

我们有一个名为:xyano_prorate.c 的程序

此代码我们需要使用 Sonarcube 运行它以识别潜在的编码错误,因为迁移后它在核心转储文件中显示分段错误。

要使用声纳分析这个程序,我需要编译它:我正在尝试使用 cmake 编译这个名为 xyano_prorate.c 的程序,以便稍后使用 sonarqube 检查它。

我创建了这个:CMakeLists.txt:

message("------------------------------")
message(" ...  Building example    ...")
message("------------------------------")


cmake_minimum_required(VERSION 3.16.3)

# The name of the executable will be : "xyano_prorate_project"
# When project(..) invoked the variable "PROJECT_NAME" will 
# have the value "xyano_prorate_project"
project(xyano_prorate_project DESCRIPTION "Testing program" LANGUAGES C)

# Set two new variables: one for src path and another for include path
# (PROJECT_SOURCE_DIR is set automatically when project(...) invoked
# its value is the path to the called CMakeLists.txt file)
set(SRC_DIR ${PROJECT_SOURCE_DIR}/src)
set(INC_DIR ${PROJECT_SOURCE_DIR}/headers)

# Nexts adds the target (executable) name and its source files
add_executable(${PROJECT_NAME} ${SRC_DIR}/xyano_prorate.c)

# Specifies the include directories for the target
target_include_directories(${PROJECT_NAME} PUBLIC "${INC_DIR}"/headers)

cmake 正在工作:

$ cmake -S .. -B ../build
CMake Warning (dev) at CMakeLists.txt:23:
  Syntax Warning in cmake code at column 63
  Argument not separated from preceding token by whitespace.
This warning is for project developers.  Use -Wno-dev to suppress it.
------------------------------
 ...  Building example    ...
------------------------------
-- The C compiler identification is GNU 13.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /builds/analytics/tam/xyanomi/target_dir/build

但是当我启动构建时它失败了:

$ /builds/group/analytics/mis/MIS-xyanomi/build-wrapper/build-wrapper-linux-x86-64 --out-dir "${BUILD_WRAPPER_OUT_DIR}" cmake --build build/ --config Release
[ 50%] Building C object CMakeFiles/xyano_prorate_project.dir/src/xyano_prorate.c.o
xyano_prorate.pgc: In function 'strlwr':
xyano_prorate.pgc:617:12: warning: implicit declaration of function 'tolower' [-Wimplicit-function-declaration]
xyano_prorate.pgc:292:1: note: include '<ctype.h>' or provide a declaration of 'tolower'
xyano_prorate.pgc: In function 'strupr':
xyano_prorate.pgc:626:13: warning: implicit declaration of function 'toupper' [-Wimplicit-function-declaration]
xyano_prorate.pgc:626:13: note: include '<ctype.h>' or provide a declaration of 'toupper'
xyano_prorate.pgc: In function 'amountFC':
xyano_prorate.pgc:2553:13: warning: 'return' with no value, in function returning non-void
xyano_prorate.pgc:2509:8: note: declared here
xyano_prorate.pgc: In function 'unloadtkt':
xyano_prorate.pgc:11002:4: warning: implicit declaration of function 'getcwd'; did you mean 'getw'? [-Wimplicit-function-declaration]
xyano_prorate.pgc:11013:4: warning: implicit declaration of function 'chdir' [-Wimplicit-function-declaration]
xyano_prorate.pgc: In function 'unload_le_reste':
xyano_prorate.pgc:11864:10: warning: type defaults to 'int' in declaration of 'BkgClass' [-Wimplicit-int]
xyano_prorate.pgc:11865:5: warning: type defaults to 'int' in declaration of 'stpo' [-Wimplicit-int]
xyano_prorate.pgc:11866:5: warning: type defaults to 'int' in declaration of 'operant' [-Wimplicit-int]
xyano_prorate.pgc: In function 'main':
xyano_prorate.pgc:13479:5: warning: 'return' with no value, in function returning non-void
xyano_prorate.pgc:13093:5: note: declared here
xyano_prorate.pgc: In function 'parcours_Hubs_Voyages':
xyano_prorate.pgc:817:7: warning: '__builtin_memcpy' writing 6 bytes into a region of size 5 overflows the destination [-Wstringop-overflow=]
xyano_prorate.pgc:634:41: note: destination object 'ArrTime1' of size 5
[100%] Linking C executable xyano_prorate_project
/usr/bin/ld: CMakeFiles/xyano_prorate_project.dir/src/xyano_prorate.c.o: in function `RollBackOrCommit':
xyano_prorate.c:(.text+0xe): undefined reference to `ECPGget_sqlca'
/usr/bin/ld: xyano_prorate.c:(.text+0x6f): undefined reference to `ECPGget_sqlca'
/usr/bin/ld: xyano_prorate.c:(.text+0x8a): undefined reference to `ECPGget_sqlca'

我发现了大量的“未定义参考”错误:

xyano_prorate.c:(.text+0xe): undefined reference to `ECPGget_sqlca'
/usr/bin/ld: xyano_prorate.c:(.text+0x6f): undefined reference to `ECPGget_sqlca'
/usr/bin/ld: xyano_prorate.c:(.text+0x8a): undefined reference to `ECPGget_sqlca'
/usr/bin/ld: xyano_prorate.c:(.text+0x93): undefined reference to `ECPGget_sqlca'
/usr/bin/ld: xyano_prorate.c:(.text+0xb3): undefined reference to `ECPGget_sqlca'
/usr/bin/ld: CMakeFiles/xyano_prorate_project.dir/src/xyano_prorate.c.o:xyano_prorate.c:(.text+0xd5): more undefined references to `ECPGget_sqlca' follow
/usr/bin/ld: CMakeFiles/xyano_prorate_project.dir/src/xyano_prorate.c.o: in function `RollBackOrCommit':
xyano_prorate.c:(.text+0x140): undefined reference to `ECPGtrans'
/usr/bin/ld: xyano_prorate.c:(.text+0x156): undefined reference to `ECPGtrans'
/usr/bin/ld: CMakeFiles/xyano_prorate_project.dir/src/xyano_prorate.c.o: in function `parcours_Hubs_Voyages':
xyano_prorate.c:(.text+0x8ac): undefined reference to `ECPGdo'
/usr/bin/ld: xyano_prorate.c:(.text+0x8b8): undefined reference to `ECPGget_sqlca'
/usr/bin/ld: xyano_prorate.c:(.text+0xa8f): undefined reference to `ECPGget_sqlca'
/usr/bin/ld: CMakeFiles/xyano_prorate_project.dir/src/xyano_prorate.c.o: in function `Enreg_in_Historique':
xyano_prorate.c:(.text+0x140c): undefined reference to `ECPGdo'
/usr/bin/ld: xyano_prorate.c:(.text+0x149d): undefined reference to `ECPGdo'
/usr/bin/ld: xyano_prorate.c:(.text+0x1562): undefined reference to `ECPGdo'
/usr/bin/ld: xyano_prorate.c:(.text+0x1618): undefined reference to `ECPGdo'
/usr/bin/ld: xyano_prorate.c:(.text+0x1b98): undefined reference to `ECPGdo'
/usr/bin/ld: CMakeFiles/xyano_prorate_project.dir/src/xyano_prorate.c.o:xyano_prorate.c:(.text+0x1e14): more undefined references to `ECPGdo' follow
/usr/bin/ld: CMakeFiles/xyano_prorate_project.dir/src/xyano_prorate.c.o: in function `Voyage_et_Destination_eScan':
xyano_prorate.c:(.text+0x1e20): undefined reference to `ECPGget_sqlca'
/usr/bin/ld: xyano_prorate.c:(.text+0x1e93): undefined reference to `ECPGget_sqlca'
/usr/bin/ld: CMakeFiles/xyano_prorate_project.dir/src/xyano_prorate.c.o: in function `Getpfm':
xyano_prorate.c:(.text+0x48c6): undefined reference to `ECPGdo'
/usr/bin/ld: xyano_prorate.c:(.text+0x48dc): undefined reference to `ECPGget_sqlca'
/usr/bin/ld: xyano_prorate.c:(.text+0x4982): undefined reference to `ECPGdo'
/usr/bin/ld: xyano_prorate.c:(.text+0x4a02): undefined reference to `ECPGdo'
/usr/bin/ld: xyano_prorate.c:(.text+0x4a7a): undefined reference to `ECPGdo'

有人可以帮助我吗?

c cmake makefile sonarqube cmakelists-options
1个回答
0
投票

使用链接器标志。您将获得未定义的参考

ECPGget_sqlca
,它是
libecpg
的一部分。因此,请在编译时调整您的 cmake 以包含链接器。

示例:

gcc -o your_executable your_source.c -lecpg -lpq

其中

-lecpg
-lpq
是链接器,它们告诉您的编译器在编译时需要包含这些库。

希望这有帮助!

© www.soinside.com 2019 - 2024. All rights reserved.