我在C
中需要一些PostgreSQL扩展的帮助我有一点测试扩展,看看有什么不起作用。 似乎cmake找到了Libraries但只能将GDAL链接到我的项目。 构建时我收到此错误消息:
/Applications/CLion.app/Contents/bin/cmake/bin/cmake --build /Users/Max/Library/Caches/clion10/cmake/generated/6306a90e/6306a90e/Debug --target Project -- -j 2
Scanning dependencies of target Project
[100%] Building C object CMakeFiles/Project.dir/main.c.o
Linking C executable Project
Undefined symbols for architecture x86_64:
"_Float4GetDatum", referenced from:
_main in main.c.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[3]: *** [Project] Error 1
make[2]: *** [CMakeFiles/Project.dir/all] Error 2
make[1]: *** [CMakeFiles/Project.dir/rule] Error 2
make: *** [Project] Error 2
的main.c
#include <postgres.h>
#include <ogr_api.h>
#include <stdio.h>
int main() {
// GDAL Function compiles without errors
OGRGeometryH g = OGR_G_CreateGeometryFromJson("POINT(0 0)");
float4 f = 4.6;
// Postgres Function doesnt work
Float4GetDatum(f);
OGR_G_DestroyGeometry(g);
printf("%f", f);
printf("Hello, World!");
return 0;
}
的CMakeLists.txt
cmake_minimum_required(VERSION 3.1)
project(Project)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror")
set(PostgreSQL_INCLUDE_DIR /usr/local/pgsql-9.1/include/server)
set(PostgreSQL_LIBRARY_DIR /usr/local/pgsql-9.1/lib)
find_package(PostgreSQL REQUIRED)
find_package(GDAL REQUIRED)
include_directories(${PostgreSQL_INCLUDE_DIR} ${GDAL_INCLUDE_DIR} )
set(SOURCE_FILES main.c)
add_executable(Project ${SOURCE_FILES})
target_link_libraries(Project ${PostgreSQL_LIBRARIES} ${GDAL_LIBRARY} )
操作系统:Mac OSX 10.10.3 Postgres:9.1.8
我正在使用CLion IDE。 顺便说一下数据库本身工作正常。
修改 输出详细
/Applications/CLion.app/Contents/bin/cmake/bin/cmake --build /Users/Max/Library/Caches/clion10/cmake/generated/6306a90e/6306a90e/Debug --target Project -- -j 2
/Applications/CLion.app/Contents/bin/cmake/bin/cmake -H/Users/Max/Development/CLionProjects/Project -B/Users/Max/Library/Caches/clion10/cmake/generated/6306a90e/6306a90e/Debug --check-build-system CMakeFiles/Makefile.cmake 0
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/Makefile2 Project
/Applications/CLion.app/Contents/bin/cmake/bin/cmake -H/Users/Max/Development/CLionProjects/Project -B/Users/Max/Library/Caches/clion10/cmake/generated/6306a90e/6306a90e/Debug --check-build-system CMakeFiles/Makefile.cmake 0
/Applications/CLion.app/Contents/bin/cmake/bin/cmake -E cmake_progress_start /Users/Max/Library/Caches/clion10/cmake/generated/6306a90e/6306a90e/Debug/CMakeFiles 1
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/Makefile2 CMakeFiles/Project.dir/all
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/Project.dir/build.make CMakeFiles/Project.dir/depend
cd /Users/Max/Library/Caches/clion10/cmake/generated/6306a90e/6306a90e/Debug && /Applications/CLion.app/Contents/bin/cmake/bin/cmake -E cmake_depends "Unix Makefiles" /Users/Max/Development/CLionProjects/Project /Users/Max/Development/CLionProjects/Project /Users/Max/Library/Caches/clion10/cmake/generated/6306a90e/6306a90e/Debug /Users/Max/Library/Caches/clion10/cmake/generated/6306a90e/6306a90e/Debug /Users/Max/Library/Caches/clion10/cmake/generated/6306a90e/6306a90e/Debug/CMakeFiles/Project.dir/DependInfo.cmake --color=
Scanning dependencies of target Project
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/Project.dir/build.make CMakeFiles/Project.dir/build
/Applications/CLion.app/Contents/bin/cmake/bin/cmake -E cmake_progress_report /Users/Max/Library/Caches/clion10/cmake/generated/6306a90e/6306a90e/Debug/CMakeFiles 1
[100%] Building C object CMakeFiles/Project.dir/main.c.o
/usr/bin/gcc -Wall -Werror -g -I/usr/local/pgsql-9.1/include/server -I/Library/Frameworks/GDAL.framework/Headers -o CMakeFiles/Project.dir/main.c.o -c /Users/Max/Development/CLionProjects/Project/main.c
Linking C executable Project
/Applications/CLion.app/Contents/bin/cmake/bin/cmake -E cmake_link_script CMakeFiles/Project.dir/link.txt --verbose=1
/usr/bin/gcc -Wall -Werror -g -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/Project.dir/main.c.o -o Project -lpq -framework gdal
Undefined symbols for architecture x86_64:
"_Float4GetDatum", referenced from:
_main in main.c.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[3]: *** [Project] Error 1
make[2]: *** [CMakeFiles/Project.dir/all] Error 2
make[1]: *** [CMakeFiles/Project.dir/rule] Error 2
make: *** [Project] Error 2
编辑2:
我的Cmake Cache中有“PostgreSQL_TYPE_INCLUDE_DIR = not found”
所以我将set(PostgreSQL_TYPE_INCLUDE_DIR /usr/local/pgsql-9.1/include/server/catalog)
添加到我的CMakeList
CMakeCache
//Path to a program.
GDAL_CONFIG:FILEPATH=/usr/local/bin/gdal-config
//Path to a file.
GDAL_INCLUDE_DIR:PATH=/Library/Frameworks/GDAL.framework/Headers
//Path to a library.
GDAL_LIBRARY:FILEPATH=/Library/Frameworks/gdal.framework
//Path to a library.
PostgreSQL_LIBRARY:FILEPATH=/usr/lib/libpq.dylib
//Internal cache
//Details about finding GDAL
FIND_PACKAGE_MESSAGE_DETAILS_GDAL:INTERNAL=[/Library/Frameworks/gdal.framework][/Library/Frameworks/GDAL.framework/Headers][v()]
//Details about finding PostgreSQL
FIND_PACKAGE_MESSAGE_DETAILS_PostgreSQL:INTERNAL=[/usr/lib/libpq.dylib][/usr/local/pgsql-9.1/include/server][/usr/local/pgsql-9.1/include/server/catalog][v9.1.8()]
//ADVANCED property for variable: PostgreSQL_LIBRARY
PostgreSQL_LIBRARY-ADVANCED:INTERNAL=1