Re: PostgreSQL C Language Extension with C++ Code

2018-08-12 Thread TalGloz
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

Re: PostgreSQL C Language Extension with C++ Code

2018-08-12 Thread TalGloz
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; }

Re: PostgreSQL C Language Extension with C++ Code

2018-08-12 Thread Tom Lane
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

Re: PostgreSQL C Language Extension with C++ Code

2018-08-12 Thread Dmitry Igrishin
вс, 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 -

Re: PostgreSQL C Language Extension with C++ Code

2018-08-12 Thread 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 -c myfunc.cpp -I/usr/pgsql-10/include/server -L"/usr/local/

Re: PostgreSQL C Language Extension with C++ Code

2018-08-12 Thread Tom Lane
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

Re: PostgreSQL C Language Extension with C++ Code

2018-08-12 Thread TalGloz
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

Re: PostgreSQL C Language Extension with C++ Code

2018-08-12 Thread Igor Korot
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

Re: PostgreSQL C Language Extension with C++ Code

2018-08-12 Thread Tom Lane
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