I'm not a C++ developer and I don't know very much about compiling projects or makefiles, but I'm trying to compile and run someone else's C++ program. I'm using Ubuntu. Here's the makefile I have so far, based on this:
TARGET_EXEC ?= a.out
BUILD_DIR ?= ./build
SRC_DIRS ?= ./src
SRCS := $(shell find $(SRC_DIRS) -name *.cpp -or -name *.c -or -name *.s)
OBJS := $(SRCS:%=$(BUILD_DIR)/%.o)
DEPS := $(OBJS:.o=.d)
INC_DIRS := $(shell find $(SRC_DIRS) -type d)
INC_FLAGS := $(addprefix -I,$(INC_DIRS))
CPPFLAGS ?= $(INC_FLAGS) -MMD -MP
CC = gcc
$(BUILD_DIR)/$(TARGET_EXEC): $(OBJS)
$(CC) $(OBJS) -o $@ $(LDFLAGS) /usr/lib/x86_64-linux-gnu/libstdc++.so.6 -I/usr/local/include/boost -I/usr/local/include/pqxx -I/usr/lib/postgresql/13/lib -I/usr/include/postgresql -I/usr/include/postgresql/libpq -I/usr/include/postgresql/internal -I/usr/include/postgresql/internal/libpq -L/usr/local/lib -lboost_filesystem -lpqxx
# assembly
$(BUILD_DIR)/%.s.o: %.s
$(MKDIR_P) $(dir $@)
$(AS) $(ASFLAGS) -c $< -o $@
# c source
# $(BUILD_DIR)/%.c.o: %.c
# $(MKDIR_P) $(dir $@)
# $(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@ -lstdc++
# c++ source
$(BUILD_DIR)/%.cpp.o: %.cpp
$(MKDIR_P) $(dir $@)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@
.PHONY: clean
clean:
$(RM) -r $(BUILD_DIR)
-include $(DEPS)
MKDIR_P ?= mkdir -p
The part commented # c++ source
seems to complete without issue, but then I run into problems with the long line above $(CC) $(OBJS) -o $@ $(LDFLAGS) ...
:
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::backendpid() const':
/usr/local/include/pqxx/src/connection_base.cxx:121: undefined reference to `PQbackendPID'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::sock() const':
/usr/local/include/pqxx/src/connection_base.cxx:129: undefined reference to `PQsocket'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::protocol_version() const':
/usr/local/include/pqxx/src/connection_base.cxx:214: undefined reference to `PQprotocolVersion'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::status() const':
/usr/local/include/pqxx/src/connection_base.cxx:965: undefined reference to `PQstatus'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::consume_input()':
/usr/local/include/pqxx/src/connection_base.cxx:501: undefined reference to `PQconsumeInput'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::is_busy() const':
/usr/local/include/pqxx/src/connection_base.cxx:507: undefined reference to `PQisBusy'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::set_verbosity(pqxx::connection_base::error_verbosity)':
/usr/local/include/pqxx/src/connection_base.cxx:551: undefined reference to `PQsetErrorVerbosity'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::err_msg() const':
/usr/local/include/pqxx/src/connection_base.cxx:660: undefined reference to `PQerrorMessage'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::set_notice_processor()':
/usr/local/include/pqxx/src/connection_base.cxx:672: undefined reference to `PQsetNoticeProcessor'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::clear_notice_processor()':
/usr/local/include/pqxx/src/connection_base.cxx:666: undefined reference to `PQsetNoticeProcessor'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::internal_set_trace()':
/usr/local/include/pqxx/src/connection_base.cxx:957: undefined reference to `PQtrace'
/usr/bin/ld: /usr/local/include/pqxx/src/connection_base.cxx:958: undefined reference to `PQuntrace'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::status() const':
/usr/local/include/pqxx/src/connection_base.cxx:965: undefined reference to `PQstatus'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::unesc_raw[abi:cxx11](char const*)':
/usr/local/include/pqxx/src/connection_base.cxx:1152: undefined reference to `PQunescapeBytea'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::status() const':
/usr/local/include/pqxx/src/connection_base.cxx:965: undefined reference to `PQstatus'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::internal::wait_read(pg_conn const*)':
/usr/local/include/pqxx/src/connection_base.cxx:129: undefined reference to `PQsocket'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::internal::wait_read(pg_conn const*, long, long)':
/usr/local/include/pqxx/src/connection_base.cxx:129: undefined reference to `PQsocket'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::internal::wait_write(pg_conn const*)':
/usr/local/include/pqxx/src/connection_base.cxx:129: undefined reference to `PQsocket'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::status() const':
/usr/local/include/pqxx/src/connection_base.cxx:965: undefined reference to `PQstatus'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::cancel_query()':
/usr/local/include/pqxx/src/connection_base.cxx:526: undefined reference to `PQgetCancel'
/usr/bin/ld: /usr/local/include/pqxx/src/connection_base.cxx:535: undefined reference to `PQcancel'
/usr/bin/ld: /usr/local/include/pqxx/src/connection_base.cxx:530: undefined reference to `PQfreeCancel'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::read_capabilities()':
/usr/local/include/pqxx/src/connection_base.cxx:1360: undefined reference to `PQserverVersion'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::protocol_version() const':
/usr/local/include/pqxx/src/connection_base.cxx:214: undefined reference to `PQprotocolVersion'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::set_client_encoding(char const*)':
/usr/local/include/pqxx/src/connection_base.cxx:1395: undefined reference to `PQsetClientEncoding'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::encoding_id() const':
/usr/local/include/pqxx/src/connection_base.cxx:1419: undefined reference to `PQclientEncoding'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::status() const':
/usr/local/include/pqxx/src/connection_base.cxx:965: undefined reference to `PQstatus'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::encrypt_password(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
/usr/local/include/pqxx/src/connection_base.cxx:94: undefined reference to `PQencryptPassword'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::quote_name(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
/usr/local/include/pqxx/src/connection_base.cxx:1180: undefined reference to `PQescapeIdentifier'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::status() const':
/usr/local/include/pqxx/src/connection_base.cxx:965: undefined reference to `PQstatus'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::clear_notice_processor()':
/usr/local/include/pqxx/src/connection_base.cxx:666: undefined reference to `PQsetNoticeProcessor'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::set_up_state()':
/usr/local/include/pqxx/src/connection_base.cxx:321: undefined reference to `PQsendQuery'
/usr/bin/ld: /usr/local/include/pqxx/src/connection_base.cxx:324: undefined reference to `PQgetResult'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::status() const':
/usr/local/include/pqxx/src/connection_base.cxx:965: undefined reference to `PQstatus'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::err_msg() const':
/usr/local/include/pqxx/src/connection_base.cxx:660: undefined reference to `PQerrorMessage'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::status() const':
/usr/local/include/pqxx/src/connection_base.cxx:965: undefined reference to `PQstatus'
/usr/bin/ld: /usr/local/include/pqxx/src/connection_base.cxx:965: undefined reference to `PQstatus'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::register_prepared(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
/usr/local/include/pqxx/src/connection_base.cxx:800: undefined reference to `PQprepare'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::start_exec(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
/usr/local/include/pqxx/src/connection_base.cxx:1079: undefined reference to `PQsendQuery'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::esc_raw[abi:cxx11](unsigned char const*, unsigned long)':
/usr/local/include/pqxx/src/connection_base.cxx:1139: undefined reference to `PQescapeByteaConn'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::reset()':
/usr/local/include/pqxx/src/connection_base.cxx:889: undefined reference to `PQreset'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::esc[abi:cxx11](char const*, unsigned long)':
/usr/local/include/pqxx/src/connection_base.cxx:1108: undefined reference to `PQescapeStringConn'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::end_copy_write()':
/usr/local/include/pqxx/src/connection_base.cxx:1054: undefined reference to `PQputCopyEnd'
/usr/bin/ld: /usr/local/include/pqxx/src/connection_base.cxx:1070: undefined reference to `PQgetResult'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::status() const':
/usr/local/include/pqxx/src/connection_base.cxx:965: undefined reference to `PQstatus'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::read_copy_line(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)':
/usr/local/include/pqxx/src/connection_base.cxx:999: undefined reference to `PQgetCopyData'
/usr/bin/ld: /usr/local/include/pqxx/src/connection_base.cxx:1007: undefined reference to `PQgetResult'
/usr/bin/ld: /usr/local/include/pqxx/src/connection_base.cxx:1009: undefined reference to `PQgetResult'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::status() const':
/usr/local/include/pqxx/src/connection_base.cxx:965: undefined reference to `PQstatus'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::consume_input()':
/usr/local/include/pqxx/src/connection_base.cxx:501: undefined reference to `PQconsumeInput'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::get_notifs()':
/usr/local/include/pqxx/src/connection_base.cxx:565: undefined reference to `PQnotifies'
/usr/bin/ld: /usr/local/include/pqxx/src/connection_base.cxx:565: undefined reference to `PQnotifies'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::parameterized_exec(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, char const* const*, int const*, int const*, int)':
/usr/local/include/pqxx/src/connection_base.cxx:1448: undefined reference to `PQexecParams'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::exec_params(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, pqxx::internal::params const&)':
/usr/local/include/pqxx/src/connection_base.cxx:1460: undefined reference to `PQexecParams'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::prepared_exec(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, char const* const*, int const*, int const*, int)':
/usr/local/include/pqxx/src/connection_base.cxx:836: undefined reference to `PQexecPrepared'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::exec_prepared(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, pqxx::internal::params const&)':
/usr/local/include/pqxx/src/connection_base.cxx:852: undefined reference to `PQexecPrepared'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::exec(char const*, int)':
/usr/local/include/pqxx/src/connection_base.cxx:715: undefined reference to `PQexec'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::status() const':
/usr/local/include/pqxx/src/connection_base.cxx:965: undefined reference to `PQstatus'
/usr/bin/ld: /usr/local/include/pqxx/src/connection_base.cxx:965: undefined reference to `PQstatus'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::exec(char const*, int)':
/usr/local/include/pqxx/src/connection_base.cxx:721: undefined reference to `PQexec'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::status() const':
/usr/local/include/pqxx/src/connection_base.cxx:965: undefined reference to `PQstatus'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::write_copy_line(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
/usr/local/include/pqxx/src/connection_base.cxx:1041: undefined reference to `PQputCopyData'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::err_msg() const':
/usr/local/include/pqxx/src/connection_base.cxx:660: undefined reference to `PQerrorMessage'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::write_copy_line(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
/usr/local/include/pqxx/src/connection_base.cxx:1046: undefined reference to `PQendcopy'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::status() const':
/usr/local/include/pqxx/src/connection_base.cxx:965: undefined reference to `PQstatus'
/usr/bin/ld: /usr/local/include/pqxx/src/connection_base.cxx:965: undefined reference to `PQstatus'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::add_receiver(pqxx::notification_receiver*)':
/usr/local/include/pqxx/src/connection_base.cxx:452: undefined reference to `PQexec'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::clear_notice_processor()':
/usr/local/include/pqxx/src/connection_base.cxx:666: undefined reference to `PQsetNoticeProcessor'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::set_notice_processor()':
/usr/local/include/pqxx/src/connection_base.cxx:672: undefined reference to `PQsetNoticeProcessor'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::get_result()':
/usr/local/include/pqxx/src/connection_base.cxx:1086: undefined reference to `PQgetResult'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::dbname()':
/usr/local/include/pqxx/src/connection_base.cxx:627: undefined reference to `PQdb'
/usr/bin/ld: /usr/local/include/pqxx/src/connection_base.cxx:627: undefined reference to `PQdb'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::username()':
/usr/local/include/pqxx/src/connection_base.cxx:636: undefined reference to `PQuser'
/usr/bin/ld: /usr/local/include/pqxx/src/connection_base.cxx:636: undefined reference to `PQuser'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::hostname()':
/usr/local/include/pqxx/src/connection_base.cxx:645: undefined reference to `PQhost'
/usr/bin/ld: /usr/local/include/pqxx/src/connection_base.cxx:645: undefined reference to `PQhost'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::port()':
/usr/local/include/pqxx/src/connection_base.cxx:654: undefined reference to `PQport'
/usr/bin/ld: /usr/local/include/pqxx/src/connection_base.cxx:654: undefined reference to `PQport'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::err_msg() const':
/usr/local/include/pqxx/src/connection_base.cxx:660: undefined reference to `PQerrorMessage'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::cancel_query() [clone .cold]':
/usr/local/include/pqxx/src/connection_base.cxx:530: undefined reference to `PQfreeCancel'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection_base.o): in function `pqxx::connection_base::err_msg() const':
/usr/local/include/pqxx/src/connection_base.cxx:660: undefined reference to `PQerrorMessage'
/usr/bin/ld: /usr/local/include/pqxx/src/connection_base.cxx:660: undefined reference to `PQerrorMessage'
/usr/bin/ld: /usr/local/include/pqxx/src/connection_base.cxx:660: undefined reference to `PQerrorMessage'
/usr/bin/ld: /usr/local/include/pqxx/src/connection_base.cxx:660: undefined reference to `PQerrorMessage'
/usr/bin/ld: /usr/local/include/pqxx/src/connection_base.cxx:660: undefined reference to `PQerrorMessage'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection.o): in function `pqxx::connectionpolicy::do_disconnect(pg_conn*)':
/usr/local/include/pqxx/src/connection.cxx:72: undefined reference to `PQfinish'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection.o): in function `pqxx::connect_async::do_startconnect(pg_conn*)':
/usr/local/include/pqxx/src/connection.cxx:116: undefined reference to `PQconnectStart'
/usr/bin/ld: /usr/local/include/pqxx/src/connection.cxx:118: undefined reference to `PQstatus'
/usr/bin/ld: /usr/local/include/pqxx/src/connection.cxx:121: undefined reference to `PQerrorMessage'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection.o): in function `pqxx::connect_async::do_completeconnect(pg_conn*)':
/usr/local/include/pqxx/src/connection.cxx:164: undefined reference to `PQconnectPoll'
/usr/bin/ld: /usr/local/include/pqxx/src/connection.cxx:164: undefined reference to `PQconnectPoll'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection.o): in function `pqxx::connectionpolicy::normalconnect(pg_conn*)':
/usr/local/include/pqxx/src/connection.cxx:38: undefined reference to `PQconnectdb'
/usr/bin/ld: /usr/local/include/pqxx/src/connection.cxx:40: undefined reference to `PQstatus'
/usr/bin/ld: /usr/local/include/pqxx/src/connection.cxx:42: undefined reference to `PQerrorMessage'
/usr/bin/ld: /usr/local/include/pqxx/src/connection.cxx:43: undefined reference to `PQfinish'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection.o): in function `pqxx::connect_direct::do_startconnect(pg_conn*)':
/usr/local/include/pqxx/src/connection.cxx:88: undefined reference to `PQstatus'
/usr/bin/ld: /usr/local/include/pqxx/src/connection.cxx:90: undefined reference to `PQerrorMessage'
/usr/bin/ld: /usr/local/lib/libpqxx.a(connection.o): in function `pqxx::connect_async::do_completeconnect(pg_conn*)':
/usr/local/include/pqxx/src/connection.cxx:146: undefined reference to `PQerrorMessage'
/usr/bin/ld: /usr/local/lib/libpqxx.a(encodings.o): in function `pqxx::internal::name_encoding(int)':
/usr/local/include/pqxx/src/encodings.cxx:633: undefined reference to `pg_encoding_to_char'
/usr/bin/ld: /usr/local/include/pqxx/src/encodings.cxx:633: undefined reference to `pg_encoding_to_char'
/usr/bin/ld: /usr/local/lib/libpqxx.a(result.o): in function `pqxx::result::size() const':
/usr/local/include/pqxx/src/result.cxx:96: undefined reference to `PQntuples'
/usr/bin/ld: /usr/local/include/pqxx/src/result.cxx:96: undefined reference to `PQntuples'
/usr/bin/ld: /usr/local/lib/libpqxx.a(result.o): in function `pqxx::result::empty() const':
/usr/local/include/pqxx/src/result.cxx:102: undefined reference to `PQntuples'
/usr/bin/ld: /usr/local/lib/libpqxx.a(result.o): in function `pqxx::result::size() const':
/usr/local/include/pqxx/src/result.cxx:96: undefined reference to `PQntuples'
/usr/bin/ld: /usr/local/include/pqxx/src/result.cxx:96: undefined reference to `PQntuples'
/usr/bin/ld: /usr/local/lib/libpqxx.a(result.o):/usr/local/include/pqxx/src/result.cxx:96: more undefined references to `PQntuples' follow
/usr/bin/ld: /usr/local/lib/libpqxx.a(result.o): in function `pqxx::result::cmd_status() const':
/usr/local/include/pqxx/src/result.cxx:273: undefined reference to `PQcmdStatus'
/usr/bin/ld: /usr/local/lib/libpqxx.a(result.o): in function `pqxx::result::affected_rows() const':
/usr/local/include/pqxx/src/result.cxx:294: undefined reference to `PQcmdTuples'
/usr/bin/ld: /usr/local/lib/libpqxx.a(result.o): in function `pqxx::result::get_is_null(unsigned long, unsigned int) const':
/usr/local/include/pqxx/src/result.cxx:312: undefined reference to `PQgetisnull'
/usr/bin/ld: /usr/local/lib/libpqxx.a(result.o): in function `pqxx::result::get_length(unsigned long, unsigned int) const':
/usr/local/include/pqxx/src/result.cxx:319: undefined reference to `PQgetlength'
/usr/bin/ld: /usr/local/lib/libpqxx.a(result.o): in function `pqxx::result::errorposition() const':
/usr/local/include/pqxx/src/result.cxx:375: undefined reference to `PQresultErrorField'
/usr/bin/ld: /usr/local/lib/libpqxx.a(result.o): in function `pqxx::result::ThrowSQLError(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const':
/usr/local/include/pqxx/src/result.cxx:153: undefined reference to `PQresultErrorField'
/usr/bin/ld: /usr/local/lib/libpqxx.a(result.o): in function `pqxx::result::columns() const':
/usr/local/include/pqxx/src/result.cxx:402: undefined reference to `PQnfields'
/usr/bin/ld: /usr/local/lib/libpqxx.a(result.o): in function `pqxx::result::column_type(unsigned int) const':
/usr/local/include/pqxx/src/result.cxx:325: undefined reference to `PQftype'
/usr/bin/ld: /usr/local/lib/libpqxx.a(result.o): in function `pqxx::result::column_table(unsigned int) const':
/usr/local/include/pqxx/src/result.cxx:336: undefined reference to `PQftable'
/usr/bin/ld: /usr/local/lib/libpqxx.a(result.o): in function `pqxx::result::columns() const':
/usr/local/include/pqxx/src/result.cxx:402: undefined reference to `PQnfields'
/usr/bin/ld: /usr/local/lib/libpqxx.a(result.o): in function `pqxx::result::table_column(unsigned int) const':
/usr/local/include/pqxx/src/result.cxx:352: undefined reference to `PQftablecol'
/usr/bin/ld: /usr/local/lib/libpqxx.a(result.o): in function `pqxx::result::columns() const':
/usr/local/include/pqxx/src/result.cxx:402: undefined reference to `PQnfields'
/usr/bin/ld: /usr/local/lib/libpqxx.a(result.o): in function `pqxx::result::size() const':
/usr/local/include/pqxx/src/result.cxx:96: undefined reference to `PQntuples'
/usr/bin/ld: /usr/local/lib/libpqxx.a(result.o): in function `pqxx::result::StatusError[abi:cxx11]() const':
/usr/local/include/pqxx/src/result.cxx:245: undefined reference to `PQresultStatus'
/usr/bin/ld: /usr/local/include/pqxx/src/result.cxx:259: undefined reference to `PQresultErrorMessage'
/usr/bin/ld: /usr/local/lib/libpqxx.a(result.o): in function `pqxx::result::inserted_oid() const':
/usr/local/include/pqxx/src/result.cxx:288: undefined reference to `PQoidValue'
/usr/bin/ld: /usr/local/lib/libpqxx.a(result.o): in function `pqxx::result::column_name(unsigned int) const':
/usr/local/include/pqxx/src/result.cxx:386: undefined reference to `PQfname'
/usr/bin/ld: /usr/local/lib/libpqxx.a(result.o): in function `pqxx::internal::clear_result(pg_result const*)':
/usr/local/include/pqxx/src/result.cxx:32: undefined reference to `PQclear'
/usr/bin/ld: /usr/local/lib/libpqxx.a(result.o): in function `pqxx::result::GetValue(unsigned long, unsigned int) const':
/usr/local/include/pqxx/src/result.cxx:304: undefined reference to `PQgetvalue'
/usr/bin/ld: /usr/local/lib/libpqxx.a(result.o): in function `pqxx::result::columns() const':
/usr/local/include/pqxx/src/result.cxx:402: undefined reference to `PQnfields'
/usr/bin/ld: /usr/local/lib/libpqxx.a(result.o): in function `pqxx::internal::clear_result(pg_result const*)':
/usr/local/include/pqxx/src/result.cxx:32: undefined reference to `PQclear'
/usr/bin/ld: /usr/local/lib/libpqxx.a(result.o): in function `pqxx::result::StatusError[abi:cxx11]() const':
/usr/local/include/pqxx/src/result.cxx:265: undefined reference to `PQresultStatus'
/usr/bin/ld: /usr/local/lib/libpqxx.a(result.o): in function `pqxx::result::columns() const':
/usr/local/include/pqxx/src/result.cxx:402: undefined reference to `PQnfields'
/usr/bin/ld: /usr/local/lib/libpqxx.a(row.o): in function `pqxx::result::column_number(char const*) const':
/usr/local/include/pqxx/src/row.cxx:209: undefined reference to `PQfnumber'
/usr/bin/ld: /usr/local/lib/libpqxx.a(util.o): in function `pqxx::describe_thread_safety()':
/usr/local/include/pqxx/src/util.cxx:35: undefined reference to `PQisthreadsafe'
/usr/bin/ld: /usr/local/lib/libpqxx.a(util.o): in function `pqxx::internal::freepqmem(void const*)':
/usr/local/include/pqxx/src/util.cxx:108: undefined reference to `PQfreemem'
collect2: error: ld returned 1 exit status
make: *** [Makefile:17: build/a.out] Error 1
From what I can tell, some necessary parts of the libpq library can't be found. I don't know if I'm supposed to be using -I
or -L
, /usr/lib/postgresql/13/
or /usr/include/postgresql
or something else, so I've just been trying different combinations, but to no avail. In addition to installing PostgreSQL, I installed libpq-dev with apt-get, but I don't know what that actually did.