Обсуждение: Linker errors while creating a PostgreSQL C extension function.
Hello, *I have this code for my C extension function. * xtern "C" { // C Headers must be inside exter "C" { } block. #include <postgres.h> #include <fmgr.h> #include <utils/builtins.h> #include <catalog/pg_type.h> #include <utils/rel.h> #include <utils/array.h> #include <stdlib.h> #include <stdint.h> PG_MODULE_MAGIC; } // CPP Header must be outside extern "C" { } block. #include <string> #include <vector> #include <iostream> #include <fstream> #include <sstream> #include <iterator> // For the ostream_iterator // External projects c++ libraries compiled and linked on running 'make'. #include <seal/seal.h> #include <thread> #include <cppcodec/base64_rfc4648.hpp> std::stringstream dec(std::string st){ // Decode the base64 string into a stringstream auto decodeBase64 = cppcodec::base64_rfc4648::decode(st); std::stringstream decodeBase64SS; std::move(decodeBase64.begin(), decodeBase64.end(), std::ostream_iterator<unsigned char>(decodeBase64SS)); return decodeBase64SS; } std::string enc(std::string st){ // Create a vector to hold the raw data std::vector<uint8_t> encodeStream; // Push all the characters from the raw data string into the vector for (auto &ch : st){ encodeStream.push_back((unsigned char&&)(ch)); } // Encode the vector as base64 string std::string encodeBase64 = cppcodec::base64_rfc4648::encode(encodeStream); encodeStream.clear(); return encodeBase64; } std::string seal_diff_operation(std::string decodedLocalEncParamTmp, std::string decodedLocalTmp1, std::string decodedLocalTmp2){ std::stringstream decodedLocalEncParam; decodedLocalEncParam.str(decodedLocalEncParamTmp); std::stringstream decodedLocalT1; decodedLocalT1.str(decodedLocalTmp1); std::stringstream decodedLocalT2; decodedLocalT2.str(decodedLocalTmp2); // Execute seal library operations // Load the ecryption parameters seal::EncryptionParameters IntegerEncryptorParms; IntegerEncryptorParms.load(decodedLocalEncParam); // Set Context and evaluator objects seal::SEALContext context(IntegerEncryptorParms); seal::Evaluator evaluator(context); // Set the Encoder parameters seal::IntegerEncoder encoder(context.plain_modulus()); // Create Ciphertexts and load Chipertext information into them seal::Ciphertext number1Encoded; seal::Ciphertext number2Encoded; seal::Ciphertext diffEncodedResult; number1Encoded.load(decodedLocalT1); number2Encoded.load(decodedLocalT2); // Do the diff operation on the Ciphertexts and prepare the result for output evaluator.sub(number1Encoded, number2Encoded, diffEncodedResult); std::stringstream encResult; diffEncodedResult.save(encResult); std::string output = enc(encResult.str()); return output; } extern "C" { // Usage of CPP functions in the module must be inside extern "C" { } block. Datum seal_diff_cpp(PG_FUNCTION_ARGS){ // Get the inputs text *t1 = PG_GETARG_TEXT_PP(0); text *t2 = PG_GETARG_TEXT_PP(1); text *encParam = PG_GETARG_TEXT_PP(2); std::string localT1; std::string localT2; std::string localEncParam; localT1 = text_to_cstring(t1); localT2 = text_to_cstring(t2); localEncParam = text_to_cstring(encParam); // Decode the parameters std::stringstream decodedLocalT1 = dec(localT1); std::stringstream decodedLocalT2 = dec(localT2); std::stringstream decodedLocalEncParam = dec(localEncParam); // Encode the parameters std::string encodedLocalT1 = enc(decodedLocalT1.str()); std::string encodedLocalT2 = enc(decodedLocalT2.str()); std::string outputParam = seal_diff_operation(decodedLocalEncParam.str(), decodedLocalT1.str(), decodedLocalT2.str()); // Return the result PG_RETURN_TEXT_P(cstring_to_text_with_len(localT1.c_str(), localT1.size())); }; PG_FUNCTION_INFO_V1(seal_diff_cpp); } *And I use this Makefile to create the seal_diff_cpp.so file: * MODULES = seal_diff_cpp PG_CONFIG = /usr/pgsql-10/bin/pg_config PGXS = $(shell $(PG_CONFIG) --pgxs) INCLUDEDIR = $(shell $(PG_CONFIG) --includedir-server) INCLUDE_SEAL = /usr/local/include/seal INCLUDE_SEAL_LIB = /usr/local/lib INCLUDE_CPPCODEC = /usr/local/include/cppcodec CXX = g++ CXXFLAGS = -std=c++17 -fPIC -Wall -Iinclude -Werror -g -O0 -pthread \ -I$(INCLUDEDIR) -I$(INCLUDE_SEAL) -I$(INCLUDE_CPPCODEC) LDFLAGS = -L$(INCLUDE_SEAL_LIB) -llibseal.a -lpthread include $(PGXS) seal_diff_cpp.so: seal_diff_cpp.o $(CXX) -Wl,--no-undefined -shared -o seal_diff_cpp.so seal_diff_cpp.o $(LDFLAGS) seal_diff_cpp.o: seal_diff_cpp.cpp $(CXX) $(CXXFLAGS) -o seal_diff_cpp.o -c seal_diff_cpp.cpp *But when I run the make command I get those linker errors * g++ -std=c++17 -fPIC -Wall -Iinclude -Werror -g -O0 -pthread -I/usr/pgsql-10/include/server -I"/usr/local/include" -o seal_diff_cpp.o -c seal_diff_cpp.cpp g++ -Wl,--no-undefined -shared -o seal_diff_cpp.so seal_diff_cpp.o -L/usr/pgsql-10/lib -L/usr/lib64 -Wl,--as-needed -Wl,-rpath,'/usr/pgsql-10/lib',--enable-new-dtags seal_diff_cpp.o: In function `seal_diff_operation(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)': /etc/opt/pgsql_c_functions/CPP/seal_extension/seal_diff_cpp.cpp:72: undefined reference to `seal::EncryptionParameters::EncryptionParameters()' /etc/opt/pgsql_c_functions/CPP/seal_extension/seal_diff_cpp.cpp:73: undefined reference to `seal::EncryptionParameters::load(std::istream&)' /etc/opt/pgsql_c_functions/CPP/seal_extension/seal_diff_cpp.cpp:75: undefined reference to `seal::SEALContext::SEALContext(seal::EncryptionParameters const&)' /etc/opt/pgsql_c_functions/CPP/seal_extension/seal_diff_cpp.cpp:76: undefined reference to `seal::Evaluator::Evaluator(seal::SEALContext const&)' /etc/opt/pgsql_c_functions/CPP/seal_extension/seal_diff_cpp.cpp:78: undefined reference to `seal::IntegerEncoder::IntegerEncoder(seal::SmallModulus const&, unsigned long)' /etc/opt/pgsql_c_functions/CPP/seal_extension/seal_diff_cpp.cpp:84: undefined reference to `seal::Ciphertext::load(std::istream&)' /etc/opt/pgsql_c_functions/CPP/seal_extension/seal_diff_cpp.cpp:85: undefined reference to `seal::Ciphertext::load(std::istream&)' /etc/opt/pgsql_c_functions/CPP/seal_extension/seal_diff_cpp.cpp:90: undefined reference to `seal::Ciphertext::save(std::ostream&) const' /etc/opt/pgsql_c_functions/CPP/seal_extension/seal_diff_cpp.cpp:78: undefined reference to `seal::IntegerEncoder::~IntegerEncoder()' /etc/opt/pgsql_c_functions/CPP/seal_extension/seal_diff_cpp.cpp:78: undefined reference to `seal::IntegerEncoder::~IntegerEncoder()' seal_diff_cpp.o: In function `seal_diff_cpp': /etc/opt/pgsql_c_functions/CPP/seal_extension/seal_diff_cpp.cpp:106: undefined reference to `pg_detoast_datum_packed' /etc/opt/pgsql_c_functions/CPP/seal_extension/seal_diff_cpp.cpp:107: undefined reference to `pg_detoast_datum_packed' /etc/opt/pgsql_c_functions/CPP/seal_extension/seal_diff_cpp.cpp:108: undefined reference to `pg_detoast_datum_packed' /etc/opt/pgsql_c_functions/CPP/seal_extension/seal_diff_cpp.cpp:112: undefined reference to `text_to_cstring' /etc/opt/pgsql_c_functions/CPP/seal_extension/seal_diff_cpp.cpp:113: undefined reference to `text_to_cstring' /etc/opt/pgsql_c_functions/CPP/seal_extension/seal_diff_cpp.cpp:114: undefined reference to `text_to_cstring' /etc/opt/pgsql_c_functions/CPP/seal_extension/seal_diff_cpp.cpp:130: undefined reference to `cstring_to_text_with_len' seal_diff_cpp.o: In function `seal::EncryptionParameters::~EncryptionParameters()': /usr/local/include/seal/encryptionparams.h:48: undefined reference to `seal::BigPoly::~BigPoly()' seal_diff_cpp.o: In function `seal::Evaluator::sub(seal::Ciphertext const&, seal::Ciphertext const&, seal::Ciphertext&)': /usr/local/include/seal/evaluator.h:205: undefined reference to `seal::Ciphertext::operator=(seal::Ciphertext const&)' /usr/local/include/seal/evaluator.h:206: undefined reference to `seal::Evaluator::sub(seal::Ciphertext&, seal::Ciphertext const&)' seal_diff_cpp.o: In function `seal::SEALContext::~SEALContext()': /usr/local/include/seal/context.h:116: undefined reference to `seal::BigUInt::~BigUInt()' collect2: error: ld returned 1 exit status make: *** [Makefile:16: seal_diff_cpp.so] Error 1 I can't figure what am I doing wrong? The SEAL library is an external library installed to /usr/local/include/seal and its libseal.a into /usr/local/lib/. I was told by the SEAL library creators (Cryptography Research Group at Microsoft), that all I need is the installd header files in /usr/local/include/seal and the libseal.a in /usr/local/lib/ so I don't understand why the linker can't link those functions. Thanks a lot, Tal -- Sent from: http://www.postgresql-archive.org/PostgreSQL-general-f1843780.html
вс, 19 авг. 2018 г. в 13:56, TalGloz <glozmantal@gmail.com>: > > Hello, > > *I have this code for my C extension function. > * > > xtern "C" { // C Headers must be inside exter "C" { } block. > #include <postgres.h> > #include <fmgr.h> > #include <utils/builtins.h> > #include <catalog/pg_type.h> > #include <utils/rel.h> > #include <utils/array.h> > #include <stdlib.h> > #include <stdint.h> > > PG_MODULE_MAGIC; > } > > // CPP Header must be outside extern "C" { } block. > #include <string> > #include <vector> > #include <iostream> > #include <fstream> > #include <sstream> > #include <iterator> // For the ostream_iterator > > // External projects c++ libraries compiled and linked on running 'make'. > #include <seal/seal.h> > #include <thread> > #include <cppcodec/base64_rfc4648.hpp> > > std::stringstream dec(std::string st){ > > // Decode the base64 string into a stringstream > auto decodeBase64 = cppcodec::base64_rfc4648::decode(st); > std::stringstream decodeBase64SS; > std::move(decodeBase64.begin(), decodeBase64.end(), > std::ostream_iterator<unsigned char>(decodeBase64SS)); > > return decodeBase64SS; > } > > std::string enc(std::string st){ > > // Create a vector to hold the raw data > std::vector<uint8_t> encodeStream; > > // Push all the characters from the raw data string into the vector > for (auto &ch : st){ > encodeStream.push_back((unsigned char&&)(ch)); > } > > // Encode the vector as base64 string > std::string encodeBase64 = > cppcodec::base64_rfc4648::encode(encodeStream); > encodeStream.clear(); > return encodeBase64; > > } > > std::string seal_diff_operation(std::string decodedLocalEncParamTmp, > std::string decodedLocalTmp1, std::string decodedLocalTmp2){ > > std::stringstream decodedLocalEncParam; > decodedLocalEncParam.str(decodedLocalEncParamTmp); > std::stringstream decodedLocalT1; > decodedLocalT1.str(decodedLocalTmp1); > std::stringstream decodedLocalT2; > decodedLocalT2.str(decodedLocalTmp2); > > // Execute seal library operations > // Load the ecryption parameters > seal::EncryptionParameters IntegerEncryptorParms; > IntegerEncryptorParms.load(decodedLocalEncParam); > // Set Context and evaluator objects > seal::SEALContext context(IntegerEncryptorParms); > seal::Evaluator evaluator(context); > // Set the Encoder parameters > seal::IntegerEncoder encoder(context.plain_modulus()); > > // Create Ciphertexts and load Chipertext information into them > seal::Ciphertext number1Encoded; > seal::Ciphertext number2Encoded; > seal::Ciphertext diffEncodedResult; > number1Encoded.load(decodedLocalT1); > number2Encoded.load(decodedLocalT2); > > // Do the diff operation on the Ciphertexts and prepare the result > for output > evaluator.sub(number1Encoded, number2Encoded, diffEncodedResult); > std::stringstream encResult; > diffEncodedResult.save(encResult); > > std::string output = enc(encResult.str()); > return output; > > } > > extern "C" { // Usage of CPP functions in the module must be inside extern > "C" { } block. > Datum seal_diff_cpp(PG_FUNCTION_ARGS){ > > // Get the inputs > text *t1 = PG_GETARG_TEXT_PP(0); > text *t2 = PG_GETARG_TEXT_PP(1); > text *encParam = PG_GETARG_TEXT_PP(2); > std::string localT1; > std::string localT2; > std::string localEncParam; > localT1 = text_to_cstring(t1); > localT2 = text_to_cstring(t2); > localEncParam = text_to_cstring(encParam); > > // Decode the parameters > std::stringstream decodedLocalT1 = dec(localT1); > std::stringstream decodedLocalT2 = dec(localT2); > std::stringstream decodedLocalEncParam = dec(localEncParam); > > // Encode the parameters > std::string encodedLocalT1 = enc(decodedLocalT1.str()); > std::string encodedLocalT2 = enc(decodedLocalT2.str()); > std::string outputParam = > seal_diff_operation(decodedLocalEncParam.str(), decodedLocalT1.str(), > decodedLocalT2.str()); > > // Return the result > PG_RETURN_TEXT_P(cstring_to_text_with_len(localT1.c_str(), > localT1.size())); > }; > > PG_FUNCTION_INFO_V1(seal_diff_cpp); > } > > > *And I use this Makefile to create the seal_diff_cpp.so file: > * > > MODULES = seal_diff_cpp > > PG_CONFIG = /usr/pgsql-10/bin/pg_config > PGXS = $(shell $(PG_CONFIG) --pgxs) > INCLUDEDIR = $(shell $(PG_CONFIG) --includedir-server) > INCLUDE_SEAL = /usr/local/include/seal > INCLUDE_SEAL_LIB = /usr/local/lib > INCLUDE_CPPCODEC = /usr/local/include/cppcodec > CXX = g++ > CXXFLAGS = -std=c++17 -fPIC -Wall -Iinclude -Werror -g -O0 -pthread \ > -I$(INCLUDEDIR) -I$(INCLUDE_SEAL) -I$(INCLUDE_CPPCODEC) > LDFLAGS = -L$(INCLUDE_SEAL_LIB) -llibseal.a -lpthread > include $(PGXS) > seal_diff_cpp.so: seal_diff_cpp.o > $(CXX) -Wl,--no-undefined -shared -o seal_diff_cpp.so > seal_diff_cpp.o $(LDFLAGS) > > seal_diff_cpp.o: seal_diff_cpp.cpp > $(CXX) $(CXXFLAGS) -o seal_diff_cpp.o -c seal_diff_cpp.cpp > > *But when I run the make command I get those linker errors > * > > g++ -std=c++17 -fPIC -Wall -Iinclude -Werror -g -O0 -pthread > -I/usr/pgsql-10/include/server -I"/usr/local/include" -o seal_diff_cpp.o -c > seal_diff_cpp.cpp > g++ -Wl,--no-undefined -shared -o seal_diff_cpp.so seal_diff_cpp.o > -L/usr/pgsql-10/lib -L/usr/lib64 -Wl,--as-needed > -Wl,-rpath,'/usr/pgsql-10/lib',--enable-new-dtags > seal_diff_cpp.o: In function > `seal_diff_operation(std::__cxx11::basic_string<char, > std::char_traits<char>, std::allocator<char> >, > std::__cxx11::basic_string<char, std::char_traits<char>, > std::allocator<char> >, std::__cxx11::basic_string<char, > std::char_traits<char>, std::allocator<char> >)': > /etc/opt/pgsql_c_functions/CPP/seal_extension/seal_diff_cpp.cpp:72: > undefined reference to `seal::EncryptionParameters::EncryptionParameters()' > /etc/opt/pgsql_c_functions/CPP/seal_extension/seal_diff_cpp.cpp:73: > undefined reference to `seal::EncryptionParameters::load(std::istream&)' > /etc/opt/pgsql_c_functions/CPP/seal_extension/seal_diff_cpp.cpp:75: > undefined reference to > `seal::SEALContext::SEALContext(seal::EncryptionParameters const&)' > /etc/opt/pgsql_c_functions/CPP/seal_extension/seal_diff_cpp.cpp:76: > undefined reference to `seal::Evaluator::Evaluator(seal::SEALContext > const&)' > /etc/opt/pgsql_c_functions/CPP/seal_extension/seal_diff_cpp.cpp:78: > undefined reference to > `seal::IntegerEncoder::IntegerEncoder(seal::SmallModulus const&, unsigned > long)' > /etc/opt/pgsql_c_functions/CPP/seal_extension/seal_diff_cpp.cpp:84: > undefined reference to `seal::Ciphertext::load(std::istream&)' > /etc/opt/pgsql_c_functions/CPP/seal_extension/seal_diff_cpp.cpp:85: > undefined reference to `seal::Ciphertext::load(std::istream&)' > /etc/opt/pgsql_c_functions/CPP/seal_extension/seal_diff_cpp.cpp:90: > undefined reference to `seal::Ciphertext::save(std::ostream&) const' > /etc/opt/pgsql_c_functions/CPP/seal_extension/seal_diff_cpp.cpp:78: > undefined reference to `seal::IntegerEncoder::~IntegerEncoder()' > /etc/opt/pgsql_c_functions/CPP/seal_extension/seal_diff_cpp.cpp:78: > undefined reference to `seal::IntegerEncoder::~IntegerEncoder()' > seal_diff_cpp.o: In function `seal_diff_cpp': > /etc/opt/pgsql_c_functions/CPP/seal_extension/seal_diff_cpp.cpp:106: > undefined reference to `pg_detoast_datum_packed' > /etc/opt/pgsql_c_functions/CPP/seal_extension/seal_diff_cpp.cpp:107: > undefined reference to `pg_detoast_datum_packed' > /etc/opt/pgsql_c_functions/CPP/seal_extension/seal_diff_cpp.cpp:108: > undefined reference to `pg_detoast_datum_packed' > /etc/opt/pgsql_c_functions/CPP/seal_extension/seal_diff_cpp.cpp:112: > undefined reference to `text_to_cstring' > /etc/opt/pgsql_c_functions/CPP/seal_extension/seal_diff_cpp.cpp:113: > undefined reference to `text_to_cstring' > /etc/opt/pgsql_c_functions/CPP/seal_extension/seal_diff_cpp.cpp:114: > undefined reference to `text_to_cstring' > /etc/opt/pgsql_c_functions/CPP/seal_extension/seal_diff_cpp.cpp:130: > undefined reference to `cstring_to_text_with_len' > seal_diff_cpp.o: In function > `seal::EncryptionParameters::~EncryptionParameters()': > /usr/local/include/seal/encryptionparams.h:48: undefined reference to > `seal::BigPoly::~BigPoly()' > seal_diff_cpp.o: In function `seal::Evaluator::sub(seal::Ciphertext const&, > seal::Ciphertext const&, seal::Ciphertext&)': > /usr/local/include/seal/evaluator.h:205: undefined reference to > `seal::Ciphertext::operator=(seal::Ciphertext const&)' > /usr/local/include/seal/evaluator.h:206: undefined reference to > `seal::Evaluator::sub(seal::Ciphertext&, seal::Ciphertext const&)' > seal_diff_cpp.o: In function `seal::SEALContext::~SEALContext()': > /usr/local/include/seal/context.h:116: undefined reference to > `seal::BigUInt::~BigUInt()' > collect2: error: ld returned 1 exit status > make: *** [Makefile:16: seal_diff_cpp.so] Error 1 > > I can't figure what am I doing wrong? The SEAL library is an external > library installed to /usr/local/include/seal and its libseal.a into > /usr/local/lib/. I was told by the SEAL library creators (Cryptography > Research Group at Microsoft), that all I need is the installd header files > in /usr/local/include/seal and the libseal.a in /usr/local/lib/ so I don't > understand why the linker can't link those functions. You didn't link against libseal upon building seal_diff_cpp.so, but you must -- I don't see something like -lseal in the g++ command string. Try to replace "-llibseal.a" with "-lseal" in LDFLAGS = -L$(INCLUDE_SEAL_LIB) -llibseal.a -lpthread
Do you mean this command: seal_diff_cpp.so: seal_diff_cpp.o $(CXX) -Wl,--no-undefined -shared -o seal_diff_cpp.so seal_diff_cpp.o $(LDFLAGS) If yes then the -lseal is added with the $(LDFLAGS) at the end of the command. -- Sent from: http://www.postgresql-archive.org/PostgreSQL-general-f1843780.html
вс, 19 авг. 2018 г. в 15:07, TalGloz <glozmantal@gmail.com>: > > Do you mean this command: > > seal_diff_cpp.so: seal_diff_cpp.o > $(CXX) -Wl,--no-undefined -shared -o seal_diff_cpp.so > seal_diff_cpp.o $(LDFLAGS) > > If yes then the -lseal is added with the $(LDFLAGS) at the end of the > command. You've defined LDFLAGS as: LDFLAGS = -L$(INCLUDE_SEAL_LIB) -llibseal.a -lpthread I mean it should be defined as: LDFLAGS = -L$(INCLUDE_SEAL_LIB) -lseal -lpthread Also, AFAIK, the command should be specified in one line, like that: seal_diff_cpp.so: seal_diff_cpp.o $(CXX) -Wl,--no-undefined -shared -o seal_diff_cpp.so seal_diff_cpp.o $(LDFLAGS)
OK, I've changed my line to LDFLAGS = -L$(INCLUDE_SEAL_LIB) -lseal -lpthread In my Makefile this command is written like this (line numbers are just for orientation) 1: seal_diff_cpp.so: seal_diff_cpp.o 2: $(CXX) -Wl,--no-undefined -shared -o seal_diff_cpp.so seal_diff_cpp.o $(LDFLAGS) 3: Or do you mean that it suppose to be like that? 1: seal_diff_cpp.so: seal_diff_cpp.o $(CXX) -Wl,--no-undefined -shared -o seal_diff_cpp.so seal_diff_cpp.o $(LDFLAGS) -- Sent from: http://www.postgresql-archive.org/PostgreSQL-general-f1843780.html
вс, 19 авг. 2018 г. в 15:46, TalGloz <glozmantal@gmail.com>: > > OK, I've changed my line to > LDFLAGS = -L$(INCLUDE_SEAL_LIB) -lseal -lpthread And? Is these flags appeared in the g++ invoking command line? I mean the following: g++ -Wl,--no-undefined -shared -o seal_diff_cpp.so seal_diff_cpp.o -L/usr/pgsql-10/lib -L/usr/lib64 -Wl,--as-needed -Wl,-rpath,'/usr/pgsql-10/lib',--enable-new-dtags > > In my Makefile this command is written like this (line numbers are just for > orientation) > > 1: seal_diff_cpp.so: seal_diff_cpp.o > 2: $(CXX) -Wl,--no-undefined -shared -o seal_diff_cpp.so > seal_diff_cpp.o $(LDFLAGS) > 3: It's correct.
No, they still don't appear there and same errors are shown. -- Sent from: http://www.postgresql-archive.org/PostgreSQL-general-f1843780.html
вс, 19 авг. 2018 г. в 15:59, TalGloz <glozmantal@gmail.com>: > > No, they still don't appear there and same errors are shown. Try to refactor your Makefile like this: LDFLAGS=-L$(INCLUDE_SEAL_LIB) LDLIBS=-lseal -lpthread seal_diff_cpp.so: seal_diff_cpp.o $(CXX) -Wl,--no-undefined -shared -o seal_diff_cpp.so $(LDFLAGS) $(LDLIBS) seal_diff_cpp.o
I'll try it later when I'm home. Is there a reason that you are linking like this $(CXX) -Wl,--no-undefined -shared -o seal_diff_cpp.so $(LDFLAGS) $(LDLIBS) seal_diff_cpp.o And not like this? $(CXX) -Wl,--no-undefined -shared -o seal_diff_cpp.so seal_diff_cpp.o $(LDFLAGS) $(LDLIBS) -- Sent from: http://www.postgresql-archive.org/PostgreSQL-general-f1843780.html
вс, 19 авг. 2018 г. в 16:20, TalGloz <glozmantal@gmail.com>: > > I'll try it later when I'm home. Is there a reason that you are linking like > this > > $(CXX) -Wl,--no-undefined -shared -o seal_diff_cpp.so $(LDFLAGS) $(LDLIBS) > seal_diff_cpp.o > > And not like this? > > $(CXX) -Wl,--no-undefined -shared -o seal_diff_cpp.so seal_diff_cpp.o > $(LDFLAGS) $(LDLIBS) If I recall correctly there were some problems with ordering arguments of the linker that are specified upon calling g++. So it is better to specify such arguments in the rest of the command. But probably this problem is already solved and there is no difference anymore.
Dmitry Igrishin <dmitigr@gmail.com> writes: > вс, 19 авг. 2018 г. в 16:20, TalGloz <glozmantal@gmail.com>: >> I'll try it later when I'm home. Is there a reason that you are linking like >> this >> $(CXX) -Wl,--no-undefined -shared -o seal_diff_cpp.so $(LDFLAGS) $(LDLIBS) >> seal_diff_cpp.o >> And not like this? >> $(CXX) -Wl,--no-undefined -shared -o seal_diff_cpp.so seal_diff_cpp.o >> $(LDFLAGS) $(LDLIBS) > If I recall correctly there were some problems with ordering arguments > of the linker that are specified upon calling g++. You're creating such problems, not solving them, if you put the library first. Particularly with .a-style libraries, you *must* list the referencing .o file first, or the linker will deem the library unreferenced and unnecessary. None of this explains the failures on the core-backend symbol references, though. What platform is this? I'm suspecting macOS or AIX, which require the postgres executable to be explicitly mentioned when linking .so's you intend to be loaded by postgres. Most other platforms leave such symbols to be resolved at runtime. It might be a good idea to see if you can't use PGXS, which will deal with a lot of these fine points for you. regards, tom lane
I'm using Fedora 28 OS and I'll check it with PGXS. The funny thing is that everything works when I comment every code line connected to the SEAL library. The cppcodec library is also an external library installed to /usr/local/include/cppcodec like the SEAL library. Regards, Tal -- Sent from: http://www.postgresql-archive.org/PostgreSQL-general-f1843780.html
вс, 19 авг. 2018 г. в 17:54, Tom Lane <tgl@sss.pgh.pa.us>: > > Dmitry Igrishin <dmitigr@gmail.com> writes: > > вс, 19 авг. 2018 г. в 16:20, TalGloz <glozmantal@gmail.com>: > >> I'll try it later when I'm home. Is there a reason that you are linking like > >> this > >> $(CXX) -Wl,--no-undefined -shared -o seal_diff_cpp.so $(LDFLAGS) $(LDLIBS) > >> seal_diff_cpp.o > >> And not like this? > >> $(CXX) -Wl,--no-undefined -shared -o seal_diff_cpp.so seal_diff_cpp.o > >> $(LDFLAGS) $(LDLIBS) > > > If I recall correctly there were some problems with ordering arguments > > of the linker that are specified upon calling g++. > > You're creating such problems, not solving them, if you put the library > first. Particularly with .a-style libraries, you *must* list the > referencing .o file first, or the linker will deem the library > unreferenced and unnecessary. Ah, I thought just the opposite :-) ! Since I use CMake I forget this subtlety. Thank you for pointing this out!
TalGloz wrote: > If yes then the -lseal is added with the $(LDFLAGS) at the end of the > command. But it doesn't happen because LDFLAGS is overriden by the makefile included just after you set it. The relevant part copy-pasted from your mail: LDFLAGS = -L$(INCLUDE_SEAL_LIB) -llibseal.a -lpthread include $(PGXS) seal_diff_cpp.so: seal_diff_cpp.o $(CXX) -Wl,--no-undefined -shared -o seal_diff_cpp.so seal_diff_cpp.o $(LDFLAGS) As as solution, you could leave LDFLAGS alone and use a different variable, or include $(PGXS) first and *append* your options to LDFLAGS if your prefer. For instance (replacing -llibseal.a with -lseal while at it): SEAL_LDFLAGS = -L$(INCLUDE_SEAL_LIB) -lseal -lpthread include $(PGXS) seal_diff_cpp.so: seal_diff_cpp.o $(CXX) -Wl,--no-undefined -shared -o seal_diff_cpp.so seal_diff_cpp.o $(LDFLAGS) $(SEAL_LDFLAGS) Best regards, -- Daniel Vérité PostgreSQL-powered mailer: http://www.manitou-mail.org Twitter: @DanielVerite
Thanks, that did the trick. But now I'm getting this g++ -Wl,--no-undefined -shared -o seal_diff_cpp.so seal_diff_cpp.o -L/usr/pgsql-10/lib -L/usr/lib64 -Wl,--as-needed -Wl,-rpath,'/usr/pgsql-10/lib',--enable-new-dtags -L/usr/local/lib -lseal -pthread /usr/bin/ld: /usr/lib64/libseal.a(bigpoly.cpp.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC /usr/bin/ld: /usr/lib64/libseal.a(biguint.cpp.o): relocation R_X86_64_32 against symbol `__pthread_key_create@@GLIBC_2.2.5' can not be used when making a shared object; recompile with -fPIC /usr/bin/ld: /usr/lib64/libseal.a(ciphertext.cpp.o): relocation R_X86_64_32 against symbol `__pthread_key_create@@GLIBC_2.2.5' can not be used when making a shared object; recompile with -fPIC /usr/bin/ld: /usr/lib64/libseal.a(context.cpp.o): relocation R_X86_64_32 against symbol `__pthread_key_create@@GLIBC_2.2.5' can not be used when making a shared object; recompile with -fPIC /usr/bin/ld: /usr/lib64/libseal.a(encoder.cpp.o): relocation R_X86_64_32S against symbol `_ZTVN4seal14IntegerEncoderE' can not be used when making a shared object; recompile with -fPIC /usr/bin/ld: /usr/lib64/libseal.a(encryptionparams.cpp.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC /usr/bin/ld: /usr/lib64/libseal.a(evaluator.cpp.o): relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a shared object; recompile with -fPIC /usr/bin/ld: /usr/lib64/libseal.a(plaintext.cpp.o): relocation R_X86_64_32 against symbol `__pthread_key_create@@GLIBC_2.2.5' can not be used when making a shared object; recompile with -fPIC /usr/bin/ld: /usr/lib64/libseal.a(randomgen.cpp.o): relocation R_X86_64_32S against symbol `_ZTVN4seal21StandardRandomAdapterISt13random_deviceEE' can not be used when making a shared object; recompile with -fPIC /usr/bin/ld: /usr/lib64/libseal.a(smallmodulus.cpp.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC /usr/bin/ld: /usr/lib64/libseal.a(baseconverter.cpp.o): relocation R_X86_64_32 against symbol `__pthread_key_create@@GLIBC_2.2.5' can not be used when making a shared object; recompile with -fPIC /usr/bin/ld: /usr/lib64/libseal.a(globals.cpp.o): relocation R_X86_64_32 against `.bss' can not be used when making a shared object; recompile with -fPIC /usr/bin/ld: /usr/lib64/libseal.a(hash.cpp.o): relocation R_X86_64_32 against symbol `_ZN4seal4util12HashFunction17sha3_round_constsE' can not be used when making a shared object; recompile with -fPIC /usr/bin/ld: /usr/lib64/libseal.a(mempool.cpp.o): relocation R_X86_64_32S against symbol `_ZTVN4seal4util12MemoryPoolSTE' can not be used when making a shared object; recompile with -fPIC /usr/bin/ld: /usr/lib64/libseal.a(modulus.cpp.o): relocation R_X86_64_32 against symbol `__gxx_personality_v0@@CXXABI_1.3' can not be used when making a shared object; recompile with -fPIC /usr/bin/ld: /usr/lib64/libseal.a(smallntt.cpp.o): relocation R_X86_64_32 against symbol `__pthread_key_create@@GLIBC_2.2.5' can not be used when making a shared object; recompile with -fPIC /usr/bin/ld: /usr/lib64/libseal.a(uintarith.cpp.o): relocation R_X86_64_32S against `.rodata' can not be used when making a shared object; recompile with -fPIC /usr/bin/ld: /usr/lib64/libseal.a(uintarithsmallmod.cpp.o): relocation R_X86_64_32 against `.bss' can not be used when making a shared object; recompile with -fPIC /usr/bin/ld: /usr/lib64/libseal.a(uintcore.cpp.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC Do I have to replace my -shared in the link command with -fPIC? -- Sent from: http://www.postgresql-archive.org/PostgreSQL-general-f1843780.html
TalGloz <glozmantal@gmail.com> writes: > Thanks, that did the trick. But now I'm getting this > /usr/bin/ld: /usr/lib64/libseal.a(bigpoly.cpp.o): relocation R_X86_64_32 > against `.rodata.str1.1' can not be used when making a shared object; > recompile with -fPIC Ugh, I was wondering if that was really going to work or not. Your copy of libseal.a has been built without relocation capability, so it can't be included in a .so library. In principle, if you have the source code for libseal, you could recompile it with -fpic or -fPIC and continue to link against the .a form of the library. But it might be better to turn it into a .so in its own right. regards, tom lane
TalGloz wrote: > Do I have to replace my -shared in the link command with -fPIC? No, but -fPIC should go into your CXXFLAGS. The pgxs makefile handles CFLAGS, but as it doesn't do C++, you're on your own for CXXFLAGS. Best regards, -- Daniel Vérité PostgreSQL-powered mailer: http://www.manitou-mail.org Twitter: @DanielVerite
My CXXFLAGS has the -fPIC flag in it. As I understood from Tom Lane's previos post, I have to recompile the libseal.a if the -fPIC flag or turn the libseal.a into a libseal.so. Best regars, Tal -- Sent from: http://www.postgresql-archive.org/PostgreSQL-general-f1843780.html
Hallo Do you or anyone know why is it trying to link with -L/usr/lib64 path and not -L/usr/local/lib as provided? After recompiling the libseal.a with the -fPIC flag and copying it manually from /usr/local/lib/ to /usr/lib64/ I get those errors: g++ -Wl,--no-undefined -shared -o seal_diff_cpp.so seal_diff_cpp.o -L/usr/pgsql-10/lib -L/usr/lib64 -Wl,--as-needed -Wl,-rpath,'/usr/pgsql-10/lib',--enable-new-dtags -L/usr/local/lib -lseal -pthread seal_diff_cpp.o: In function `seal_diff_cpp': /etc/opt/pgsql_c_functions/CPP/seal_extension/seal_diff_cpp.cpp:106: undefined reference to `pg_detoast_datum_packed' /etc/opt/pgsql_c_functions/CPP/seal_extension/seal_diff_cpp.cpp:107: undefined reference to `pg_detoast_datum_packed' /etc/opt/pgsql_c_functions/CPP/seal_extension/seal_diff_cpp.cpp:108: undefined reference to `pg_detoast_datum_packed' /etc/opt/pgsql_c_functions/CPP/seal_extension/seal_diff_cpp.cpp:112: undefined reference to `text_to_cstring' /etc/opt/pgsql_c_functions/CPP/seal_extension/seal_diff_cpp.cpp:113: undefined reference to `text_to_cstring' /etc/opt/pgsql_c_functions/CPP/seal_extension/seal_diff_cpp.cpp:114: undefined reference to `text_to_cstring' /etc/opt/pgsql_c_functions/CPP/seal_extension/seal_diff_cpp.cpp:130: undefined reference to `cstring_to_text_with_len' Did I miss something in one of my files? Best regards, Tal -- Sent from: http://www.postgresql-archive.org/PostgreSQL-general-f1843780.html
TalGloz wrote: > Do you or anyone know why is it trying to link with -L/usr/lib64 path and > not -L/usr/local/lib as provided? > > After recompiling the libseal.a with the -fPIC flag and copying it manually > from /usr/local/lib/ to /usr/lib64/ I get those errors: > > g++ -Wl,--no-undefined -shared -o seal_diff_cpp.so seal_diff_cpp.o > -L/usr/pgsql-10/lib -L/usr/lib64 -Wl,--as-needed > -Wl,-rpath,'/usr/pgsql-10/lib',--enable-new-dtags -L/usr/local/lib -lseal > -pthread > seal_diff_cpp.o: In function `seal_diff_cpp': > /etc/opt/pgsql_c_functions/CPP/seal_extension/seal_diff_cpp.cpp:106: > undefined reference to `pg_detoast_datum_packed' > /etc/opt/pgsql_c_functions/CPP/seal_extension/seal_diff_cpp.cpp:107: > undefined reference to `pg_detoast_datum_packed' > /etc/opt/pgsql_c_functions/CPP/seal_extension/seal_diff_cpp.cpp:108: > undefined reference to `pg_detoast_datum_packed' > /etc/opt/pgsql_c_functions/CPP/seal_extension/seal_diff_cpp.cpp:112: > undefined reference to `text_to_cstring' > /etc/opt/pgsql_c_functions/CPP/seal_extension/seal_diff_cpp.cpp:113: > undefined reference to `text_to_cstring' > /etc/opt/pgsql_c_functions/CPP/seal_extension/seal_diff_cpp.cpp:114: > undefined reference to `text_to_cstring' > /etc/opt/pgsql_c_functions/CPP/seal_extension/seal_diff_cpp.cpp:130: > undefined reference to `cstring_to_text_with_len' > > Did I miss something in one of my files? I think the --no-undefined is wrong. Any reference to PostgreSQL functions is undefined at build time and gets resolved when the shared library is loaded into PostgreSQL. Yours, Laurenz Albe -- Cybertec | https://www.cybertec-postgresql.com
I removed the flag --no-undefined and it was compiled and worked like a charm. I needed the flag to spot the linker errors for linking with the external *libseal.a* library. As for my other question regarding the unused linker path *-L"/usr/local/lib"*. I'm using Fedora 28 (RedHat) and in this distribution the default path for libs is /usr/lib64, so I can use this setting or change it to include the */usr/local/lib* path as well. Best regards, Tal -- Sent from: http://www.postgresql-archive.org/PostgreSQL-general-f1843780.html