Skip to content

Instantly share code, notes, and snippets.

@Shawn-Armstrong
Last active February 2, 2023 21:03
Show Gist options
  • Save Shawn-Armstrong/3aca632ce26535ab311135194079019b to your computer and use it in GitHub Desktop.
Save Shawn-Armstrong/3aca632ce26535ab311135194079019b to your computer and use it in GitHub Desktop.

#C_libpq_linking_error.md

  • Issue was resolved.
  • Solution was performed on Ubuntu 20.04 using WSL2 for Windows10.
  • Compilation command needed a path to libpq resources for linking.
    • The default path to this directory is typically /usr/include/postgresql.

Test file

// test.c
#include <stdio.h>
#include <stdlib.h>
#include <libpq-fe.h>

int main(int argc, char **argv){
	printf("\nHello World\n\n");
	return 0;
}

Error

$ gcc test.c -lpq -o test
test.c:3:10: fatal error: libpq-fe.h: No such file or directory
    3 | #include <libpq-fe.h>
      |          ^~~~~~~~~~~~
compilation terminated.

Solution

# Required Bash commands
sudo apt update
sudo apt-get install libpq-dev
gcc test.c -I/usr/include/postgresql -lpq -o test
./test

Hello World
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment