2

I'm working on a project and trying to compile my code. I just moved this code from windows (VC++) to linux and it worked fine on windows but I can't get it to compile on linux.

The program uses zeromq for TCP connections and I am getting multiple errors when I build. Errors of the type:

/usr/local/include/zmq.hpp:372: undefined reference to `zmq_bind'
/usr/local/include/zmq.hpp:415: undefined reference to `zmq_msg_send'

I've installed zeromq via its tarball on my linux machine, and manually added zmq.hpp to the /usr/local/include folder. I suspect that I am doing something wrong in my makefile and thats why I am getting these errors.

I am somewhat weak in creating makefiles so I would greatly appreciate if someone can take a look for me and tell me if there is an obvious issue with my makefile that is causing these issues. Here is my makefile

C = g++
DEBUG = -g
CFLAGS = -g -Wall -std=c++11
LFLAGS = -L/usr/local/lib/

INCLUDES = -I/usr/local/

LIBS = -libzmq.la

SRCS = main.cpp NetworkTestServer.cpp

OBJS = $(SRCS:.cpp=.o)

EXECUTABLE = tester

all: $(SRCS) $(EXECUTABLE) 

$(EXECUTABLE): $(OBJS)
    $(CC) $(EXECUTABLE) -o $(EXECUTABLE) $(LIBS)

.cpp.o:
    $(CC) $(CFLAGS) $< -o $@

clean:
    $(RM) *.o *~ $(EXECUTABLE)

Thanks much

Sergei Nikulov
  • 5,029
  • 23
  • 36
SilverBackApe
  • 227
  • 4
  • 15
  • possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – KillianDS Jan 27 '14 at 13:30
  • You don't link the `.la` file. That file is a special description of the library produced by libtool, not the library itself. You link the `.a` file. And, the syntax you are using is incorrect; see Tyler's answer. – MadScientist Jan 27 '14 at 13:58
  • Thanks KillianDS I didn't think it was really a duplicate cause I was specifically asking about my makefile – SilverBackApe Jan 27 '14 at 14:11

1 Answers1

3

Looks to me like your LIBS definition is wrong.

Typically, the lib part is omitted, along with the extension. So, try something like:

LIBS = -lzmq

If that doesn't work, ensure that this library is contained in the location as specified by your LFLAGS variable.

Tyler Jandreau
  • 4,245
  • 1
  • 22
  • 47
  • Thanks Tyler, I had that configuration initially but the same issues occurred. I just switched the LIBS = -lzmq but i'm still getting the same errors. I will post the contents of my folder defined in LFLAGS – SilverBackApe Jan 27 '14 at 14:15
  • The folder referenced in LFLAGS looks like: '/usr/local/lib$ ls libzmq.a libzmq.so libzmq.so.3.1.0 python2.7 libzmq.la libzmq.so.3 pkgconfig python3.3' – SilverBackApe Jan 27 '14 at 14:17
  • 1
    Your link line is wrong. You have `$(CC) $(EXECUTABLE) -o $(EXECUTABLE) $(LIBS)`. It should be `$(CC) $(OBJS) -o $(EXECUTABLE) $(LFLAGS) $(LIBS)`. Also your compile line is wrong; you're missing the `-c` flag. It should be `$(CC) $(CFLAGS) -o $@ -c $<`. If this doesn't help please update your answer with a cut and paste of the actual link line that make prints out before you get the error so we can see what's wrong with it. – MadScientist Jan 27 '14 at 15:15
  • THANKS!! Compiled successfully with no errors after adding your last change combined with changing the LIBS = ... Thank you all for your help, this is much appreciated. – SilverBackApe Jan 27 '14 at 16:12
  • Just one last question, how did you determine the order of the link line vars as well as the compile line? All the makefile examples i see use different orders for those and don't really explain the train of thought behind them, so for future reference please share. Thanks – SilverBackApe Jan 27 '14 at 16:14