Re: [Fwd: `undefined reference` Error When Linking]

Marco Atzeri <[email protected]>
Newsgroups gmane.comp.gnu.glpk
Message-ID <[email protected]>
On 26/03/2018 01:39, Andrew Makhorin wrote:

-------- Forwarded Message --------
From: Lam Ling
> Hi all,
> 
> 
> I built and installed glpk 4.65 from source, and I can verify that it's
> successfully installed to `/usr/local/lib`. But when I tried to compile
> a C++ program with glpk using gcc 5.4.0 on Ubuntu 16.04, I got many
> undefined reference errors on the glpk functions.
> 
> 
> Here's the g++ command I used:
> 
> 
> g++ -I/home/linuxbrew/.linuxbrew/Cellar/eigen/3.3.4/include/eigen3
> -I/usr/local/include -lm -L/usr/local/lib -lglpk -Wall -Ofast -std=c++11
> util.cpp main.cpp -o main
> 

link order matters, try

g++ -I/home/linuxbrew/.linuxbrew/Cellar/eigen/3.3.4/include/eigen3
-I/usr/local/include -lm -L/usr/local/lib util.cpp main.cpp
-lglpk -Wall -Ofast -std=c++11 -o main
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.