dimanche 19 avril 2015

CMake Cannot link postgres Libraries

I need some help with postgres extensions in C


I have a little test-expansion to see if something doesn't work. It seems that cmake finds the Libraries but can only link GDAL to my project. When building I get this error message:



/Applications/http://ift.tt/1Itdw3K --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} )


OS: Mac OSX 10.10.3 Postgres: 9.1.8


I´m using the CLion IDE. Btw the Database itself works fine.


Aucun commentaire:

Enregistrer un commentaire