Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带C的Postgres导致非零退出代码_C_Postgresql - Fatal编程技术网

带C的Postgres导致非零退出代码

带C的Postgres导致非零退出代码,c,postgresql,C,Postgresql,我正在尝试用C语言处理postgres数据库。我使用cmake成功导入了它,尽管当我运行任何与libpq-fe相关的代码时,比如下面的示例,我会得到非零的退出代码 int main(int argc, char *argv[]) { printf("Before version\n"); int lib_ver = PQlibVersion(); return 0; } 以下是错误: 过程结束,退出代码为-1073741515(0xC0000135)

我正在尝试用C语言处理postgres数据库。我使用cmake成功导入了它,尽管当我运行任何与libpq-fe相关的代码时,比如下面的示例,我会得到非零的退出代码

int main(int argc, char *argv[]) {
    printf("Before version\n");
    int lib_ver = PQlibVersion();
    return 0;
}
以下是错误: 过程结束,退出代码为-1073741515(0xC0000135)

我还想指出,它甚至不打印第一行。 我做错了什么

编辑: 为了澄清,这里是我的CMakeLists.txt文件:

cmake_minimum_required(VERSION 3.10)
project(importer C)

set(CMAKE_C_STANDARD 99)

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -I${PROJECT_SOURCE_DIR}/libs/pgsql/include -L/${PROJECT_SOURCE_DIR}/libs/pgsql/lib")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I${PROJECT_SOURCE_DIR}/libs/pgsql/include")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L${PROJECT_SOURCE_DIR}/libs/pgsql/lib")

# Next line is not required, without it given path will be checked too.
set(PostgreSQL_ROOT "${PROJECT_SOURCE_DIR}/libs/pgsql")
find_package(PostgreSQL REQUIRED)

include_directories (${PostgreSQL_INCLUDE_DIRS})
link_directories(${PostgreSQL_LIBRARY_DIRS})

set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)

set(SOURCES main.c)
add_executable(importer ${SOURCES})
target_link_libraries(importer PRIVATE ${PostgreSQL_LIBRARIES})
target_link_libraries(importer PRIVATE Threads::Threads)

set(SOURCE_FILES CMakeLists.txt main.c)
下面是解析cmake的输出:

"C:\Program Files\JetBrains\CLion 2018.3\bin\cmake\win\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - MinGW Makefiles" C:\Users\lukas\school\ing\pdt\importer
-- The C compiler identification is GNU 8.1.0
-- Check for working C compiler: C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/gcc.exe
-- Check for working C compiler: C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/gcc.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
CMake Warning (dev) at CMakeLists.txt:12 (find_package):
  Policy CMP0074 is not set: find_package uses <PackageName>_ROOT variables.
  Run "cmake --help-policy CMP0074" for policy details.  Use the cmake_policy
  command to set the policy and suppress this warning.

  CMake variable PostgreSQL_ROOT is set to:

    C:/Users/lukas/school/ing/pdt/importer/libs/pgsql

  For compatibility, CMake is ignoring the variable.
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Found PostgreSQL: C:/Users/lukas/school/ing/pdt/importer/libs/pgsql/lib/libpq.dll (found version "12.4") 
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - found
-- Found Threads: TRUE  
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/lukas/school/ing/pdt/importer/cmake-build-debug

[Finished]
 
“C:\Program Files\JetBrains\CLion 2018.3\bin\cmake\win\bin\cmake.exe”-DCMAKE\u BUILD\u TYPE=Debug-G”代码块-MinGW Makefiles“C:\Users\lukas\school\ing\pdt\importer”
--C编译器标识为GNU8.1.0
--检查C编译器是否工作:C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/gcc.exe
--检查C编译器是否工作:C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/gcc.exe--工作正常
--检测C编译器ABI信息
--检测C编译器ABI信息-完成
--检测C编译特性
--检测C编译特性-完成
CMakeLists.txt:12上的CMake警告(dev)(查找程序包):
未设置策略CMP0074:find_包使用_根变量。
运行“cmake--帮助策略CMP0074”获取策略详细信息。使用cmake_策略
命令设置策略并抑制此警告。
CMake变量PostgreSQL\u ROOT设置为:
C:/Users/lukas/school/ing/pdt/importer/libs/pgsql
为了兼容性,CMake忽略了变量。
此警告适用于项目开发人员。使用-Wno-dev来抑制它。
--找到PostgreSQL:C:/Users/lukas/school/ing/pdt/importer/libs/pgsql/lib/libpq.dll(找到版本“12.4”)
--正在查找pthread.h
--正在查找pthread.h-找到
--正在查找pthread_create
--正在查找pthread_create-找到
--找到的线程:TRUE
--配置完成
--生成完成
--生成文件已写入:C:/Users/lukas/school/ing/pdt/importer/cmake Build debug
[已完成]

因此,您可以看到.dll就在那里。另外,当我使用WSL编译它时,它可以工作,但不能与mingw一起工作。

最有可能的情况是,libpq不能在运行时动态链接,或者动态链接的版本与构建程序的版本不同。例如,如果在构建时链接到libpq的个人副本,或者在构建程序后删除或更新libpq,则可能会发生上述任何一种情况。或者,您的libpq可能有故障。或者程序失败可能是调用以前未声明的函数(
PQlibVersion()
)时产生的未定义行为的外在表现。您可以尝试使用特定于操作系统的动态库检查器,如
otool
ldd
,查看它是否报告任何问题。不确定Windows的DLL等效项是什么。0xC0000135==状态\u DLL\u未找到,您缺少使用库所需的DLL。所以你可以在谷歌上搜索“postgresql windows dll not found”,这会占用你的时间。我想从项目中链接postgres库,我如何将编译器指向它?