Linking boost libraries in makefile under cygwin

by DartLenin   Last Updated November 08, 2018 23:26 PM

I'm trying to link my program with boost libraries using makefile with cygwin. Here is my makefile:

CXX = g++
CXXFLAGS = -Wno-signed-compare -Wall -std=c++11 -funsigned-char -I /cygdrive/e/boost/include/boost-1_55/boost 
LNKFLAGS = -L cygdrive/e/boost/lib

SRCDIR = src
OUTDIR = bin

EXEC = $(OUTDIR)/prg
SOURCES = $(wildcard src/*.cpp)

all: $(EXEC)

    $(CXX) $(LNKFLAGS) $(OBJECTS) -o $(EXEC) -l boost_thread

$(OBJECTS): $(OUTDIR)/%.o : $(SRCDIR)/%.cpp
    mkdir -p $(OUTDIR)
    $(CXX) $(CXXFLAGS) -c -O3 $< -o [email protected]

    rm -rf $(OUTDIR)

.PHONY: clean


$ make  
g++ -L cygdrive/e/boost/lib bin/test.o -o bin/prg -l boost_thread
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: cannot find -lboost_thread

What's wrong? What should I specify?

Answers 1

  1. In your Makefile the library search path is relative, but should be absolute in this case.

    LNKFLAGS = -L/cygdrive/e/boost/lib
  2. Check if /cygdrive/e/boost/lib really contains Boost libraries built with the GCC toolchain.

    • libboost_thread.a or will work.
    • Libraries built with the Visual C++ toolchain ending with .lib or .dll will not work.
  3. Check if the filename matches.

    • -lboost_thread requires that the library is named either libboost_thread.a or
    • libboost_thread-mt.a or the like will not work.
  4. You may find my answer to a related question helpful.

Martin Trenkmann
Martin Trenkmann
November 08, 2018 23:23 PM

Related Questions

Running make in Cygwin does... nothing?

Updated August 12, 2017 15:26 PM

How to redirect cygwin console output to a file

Updated November 25, 2017 11:26 AM

How to install GMP Mp on windows? (C++)

Updated October 08, 2018 06:26 AM