OK It worked. This is how I did it, hopefully it is right
extern "C" {
#include
#include
#include
#include
#include
#include
#include
#include
PG_MODULE_MAGIC;
}
#include
#include
#include
#include
#include // external compiled c++ library linked on running
'make'
extern "C" {
Dat
Let me see if I understood you correctly. I cant have a code like this:
extern "C" {
int sum_of_numbers(){
std::vector numbers {23, 445, 64};
int sum = 0;
for (auto &item : numbers){
sum += item;
}
TalGloz writes:
> But now my compiler throws some other errors when running make:
> myfunc.cpp:29:10: error: conflicting declaration of C function ‘int64_t
> sum_of_numbers()’
> int64_t sum_of_numbers(){
> ^~
Well, yeah, you forgot to repeat the argument list here. For t
вс, 12 авг. 2018 г. в 21:40, TalGloz :
>
> I did it with the macros
>
> extern "C" {
> Datum sum_of_numbers(PG_FUNCTION_ARGS);
> PG_FUNCTION_INFO_V1(sum_of_numbers);
> }
>
> But now my compiler throws some other errors when running make:
>
> g++ --std=c++17 -fPIC -Wall -Werror -g3 -O0 -o myfunc.o -
I did it with the macros
extern "C" {
Datum sum_of_numbers(PG_FUNCTION_ARGS);
PG_FUNCTION_INFO_V1(sum_of_numbers);
}
But now my compiler throws some other errors when running make:
g++ --std=c++17 -fPIC -Wall -Werror -g3 -O0 -o myfunc.o -c myfunc.cpp
-I/usr/pgsql-10/include/server -L"/usr/local/
TalGloz writes:
> The error this time for PostgreSQL is:
> *ERROR: could not find function information for function "sum_of_numbers"
> HINT: SQL-callable functions need an accompanying
> PG_FUNCTION_INFO_V1(funcname).
> SQL state: 42883*
Probably need extern "C" around the PG_FUNCTION_INFO_V1 m
OK now I have this code:
1: extern "C" { // The C header should go here
2: #include
3: #include
4: #include
5: #include
6: #include
7: #include
8: #include
9: #include
10:
11: PG_MODULE_MAGIC;
12: }
13:
14: // CPP header without extern "C"
15: #include
16: #include
1
Hi,
On Sun, Aug 12, 2018 at 12:05 PM, TalGloz wrote:
> Hi,
>
> I've searched information about my problem in the archives and on the
> internet, but it didn't help. I have this small myfunc.cpp
>
> 1: #include
> 2: #include
> 3: #include
> 4: #include
> 5: #include
> 6: #include
TalGloz writes:
> I've searched information about my problem in the archives and on the
> internet, but it didn't help. I have this small myfunc.cpp
> [ that doesn't work ]
> 16: #ifdef PG_MODULE_MAGIC
> 17: PG_MODULE_MAGIC;
> 18: #endif
Hmm ... don't use an #ifdef there. If you don't have the