Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fotoO-0001hq-EG for pgsql-general@arkaria.postgresql.org; Sun, 12 Aug 2018 17:05:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fotoK-0003xW-16 for pgsql-general@arkaria.postgresql.org; Sun, 12 Aug 2018 17:05:48 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fotoJ-0003xP-I1 for pgsql-general@lists.postgresql.org; Sun, 12 Aug 2018 17:05:47 +0000 Received: from n3.nabble.com ([162.255.23.22]) by makus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fotoB-0000ko-R4 for pgsql-general@postgresql.org; Sun, 12 Aug 2018 17:05:45 +0000 Received: from n3.nabble.com (localhost [127.0.0.1]) by n3.nabble.com (Postfix) with ESMTP id CA7FFE848E03 for ; Sun, 12 Aug 2018 10:05:38 -0700 (MST) Date: Sun, 12 Aug 2018 10:05:38 -0700 (MST) From: TalGloz To: pgsql-general@postgresql.org Message-ID: <1534093538827-0.post@n3.nabble.com> Subject: PostgreSQL C Language Extension with C++ Code MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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 7: #include 8: #include 9: #include 10: #include 11: #include 12: #include 13: #include 14: #include // external compiled c++ library linked on running 'make' 15: 16: #ifdef PG_MODULE_MAGIC 17: PG_MODULE_MAGIC; 18: #endif 19: 20: Datum sum_of_numbers(PG_FUNCTION_ARGS); 21: PG_FUNCTION_INFO_V1(sum_of_numbers); 22: 23: extern "C" { 24: int64_t sum_of_numbers(){ 25: std::vector numbers {23, 445, 64}; 26: auto sum = 0; 27: for (auto &item : numbers){ 28: sum += item; 29: } 30: return sum; 31: } 32: } And I compile without any problem suing this Makefiles: 1: MODULES = myfunc 2: 3: PG_CONFIG = /usr/pgsql-10/bin/pg_config 4: PGXS = $(shell $(PG_CONFIG) --pgxs) 5: INCLUDEDIR = $(shell $(PG_CONFIG) --includedir-server) 6: INCLUDE_SEAL = /usr/local/include/seal 7: INCLUDE_SEAL_LIB = /usr/local/lib/libseal.a 8: INCLUDE_CPPCODEC = /usr/local/include/cppcodec 9: #CFLAGS = -std=c11 10: #CFLAGS = --std=c++14 -fPIC -Wall -Werror -g3 -O0 11: include $(PGXS) 12: myfunc.so: myfunc.o 13: g++ -shared -o myfunc.so myfunc.o 14: 16: myfunc.o: myfunc.cpp 17: g++ --std=c++17 -fPIC -Wall -Werror -g3 -O0 -o myfunc.o -c myfunc.cpp -I$(INCLUDEDIR) -L$(INCLUDE_SEAL_LIB) -I$(INCLUDE_SEAL) -I$(INCLUDE_CPPCODEC) 18: After copying the myfunc.so file to the PostgreSQL lib folder and executing: 1: CREATE OR REPLACE FUNCTION 2: sum_of_numbers() RETURNS integer AS 'myfunc' 3: LANGUAGE C STRICT; I get this error: *ERROR: incompatible library "/usr/pgsql-10/lib/myfunc.so": missing magic block HINT: Extension libraries are required to use the PG_MODULE_MAGIC macro. SQL state: XX000* I've added the files and line numbers for an easier discussion. Thanks a lot, Tal myfunc.cpp Makefiles.Makefiles -- Sent from: http://www.postgresql-archive.org/PostgreSQL-general-f1843780.html