Answer the question
In order to leave comments, you need to log in
How to set up a cmake project in QtCreator to work with postgres *.pgc files?
Hello.
I want to make an interface for a training database using ecpg. I would like to create a project in QtCreator using cmake, and edit everything in it, incl. *.pgc files. I tried, but it didn't work. Tell me what needs to be added / corrected in the project settings.
CMakeLists.txt :
cmake_minimum_required(VERSION 2.8)
project(cmake_sample)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -W all")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I /opt/PostgreSQL/9.4/include -L /opt/PostgreSQL/9.4/lib -l ecpg")
set( PGSQL_CMD "/usr/bin/ecpg" )
set( PGSQL_ARG "ecpg.pgc" )
add_custom_command( OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/ecpg.c
COMMAND ${PGSQL_CMD} ${PGSQL_ARG}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/ecpg.pgc
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} )
aux_source_directory(. SRC_LIST)
add_executable(${PROJECT_NAME} ${SRC_LIST} "ecpg.h" "ecpg.pgc")
//ecpg.h
extern "C" {
void ConnectToDB();
}
//ecpg.pgc
#include "ecpg.h"
void ConnectToDB()
{
EXEC SQL BEGIN DECLARE SECTION;
char ConnectionString [] = "[email protected]:5432";
char Login [] = "login";
char Password [] = "pass";
EXEC SQL END DECLARE SECTION;
EXEC SQL CONNECT TO :ConnectionString USER :Login using :Password;
}
//main.cpp
#include "ecpg.h"
int main()
{
ConnectToDB();
return 0;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question