help-glpk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-glpk] Linking errors when using cfg.h in a MacOs X


From: Jose L Walteros
Subject: [Help-glpk] Linking errors when using cfg.h in a MacOs X
Date: Wed, 18 Jun 2014 00:02:00 -0400

Hi all, 

I tried to send this before and I think it didn't work. I am sorry if you receive it again.

I have been working on a code for a while that uses the conflict graph libraries of GLPK. The code compiles perfectly in a Linux machine. However, when I try to compile it on a MacOS X (via the console) I get some linking errors. 

To give you an idea of my problem, I attached bellow a makefile and two trivial applications: main1.cpp is an application that reads clique4.lp, generates the conflict graph, and prints the number of vertices of such graph. As I mentioned, the code compiles perfectly in Linux using the same makefile (after updating the corresponding paths). In MacOS X, I get the following error:

-----------------------------------------
Undefined symbols for architecture x86_64:
  "__glp_cfg_build_graph", referenced from:
      _main in main1-5183c5.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [main1] Error 1
-----------------------------------------

To make sure there was no issues with the installation of GLPK or the path to the libraries, I created main2.cpp, which is an applications that simply reads and solves clique4.lp. Contrary to the previous case, main2.cpp compiles and runs perfectly.

I have tried many things, but I haven't been able to make it work. I hope you guys can help.

Regards, 

Attachments:

-----------------------------------------
main1.cpp
-----------------------------------------
#include <iostream>
extern "C" {
#include <glpk.h>
#include "cfg.h"
    #include "env.h"
    #include "prob.h"
}

int main(int argc, const char * argv[])
{
    glp_prob *P;
CFG *G;
int nV, v, u, degree;

    P = glp_create_prob();
glp_read_lp(P, NULL, "./clique4.lp");
G = cfg_build_graph(P); 

nV = G->nv;

std::cout<<"# vertices: "<<nV<<std::endl;

int *ref = G->ref;
int *neg = G->neg;
int *pos = G->pos;

for (v = 1; v <= nV; v++){  
std::cout<<"vertex "<<v<<" --> variable "<<ref[v]<<"\n";
std::cout<<" pos "<<pos[ref[v]]<<" neg "<<neg[ref[v]]<<"\n";
}

    return 0;
}
-----------------------------------------
main2.cpp
-----------------------------------------

#include <iostream>
extern "C" {
#include <glpk.h>
}

int main(int argc, const char * argv[])
{
    glp_prob *P;

    P = glp_create_prob();
glp_read_lp(P, NULL, "./clique4.lp");
    glp_simplex(P, NULL);

    return 0;
}
-----------------------------------------
Makefile
-----------------------------------------

CPP          = g++
ARGS         = -m64 -g
GLPKPATH     = /Users/jwalteros/Applications/GLPK/glpk-4.54
GLPKLIBPATH  = /usr/local
GLPK         = $(GLPKLIBPATH)/include/
GLPKSRC      = $(GLPKPATH)/src/
GLPKCGLIB    = $(GLPKPATH)/src/cglib/
GLPKENV      = $(GLPKPATH)/src/env/
GLPKMISC     = $(GLPKPATH)/src/misc/
LIBGLPK      = $(GLPKLIBPATH)/lib/

all: main1 main2

main1:
$(CPP) $(ARGS) -o main1 main1.cpp -I$(GLPK) -I$(GLPKSRC) -I$(GLPKCGLIB) \
-I$(GLPKENV) -I$(GLPKENV) -I$(GLPKMISC) -L$(LIBGLPK) -lglpk

main2:
$(CPP) $(ARGS) -o main2 main2.cpp -I$(GLPK) -L$(LIBGLPK) -lglpk

-----------------------------------------

reply via email to

[Prev in Thread] Current Thread [Next in Thread]