home › Forums › # Technical Support › Linking against fuzzylite: undefined reference errors › Reply To: Linking against fuzzylite: undefined reference errors
Hi Juan,
I finally got it working be recompiling fuzzylite (5.0) with the mingw-gcc compiler under Window 7.
The fuzzylite sources can be compiled when build.bat and the CMakeLists.txt are slightly modified.
build.bat:
cmake .. -G"Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DFL_BACKTRACE=OFF -DFL_USE_FLOAT=OFF -DFL_CPP11=OFF -DCMAKE_CXX_COMPILER=C:/Programs/Rtools/gcc-4.6.3/bin/g++.exe
make
# instead of
cmake .. -G"NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DFL_BACKTRACE=OFF -DFL_USE_FLOAT=OFF -DFL_CPP11=OFF
nmake
CMakeLists.txt:
if(WIN32)
set(CMAKE_CXX_FLAGS "-pedantic -Wall -Wextra")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
if(NOT APPLE)
set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--no-undefined")
endif()
...
# instead of
if(WIN32)
set(CMAKE_CXX_FLAGS "/WX /W4 /EHsc")
...
In fact, the compilation looks more like “Linux” which is due to different command line options of the compiler and make system used.
Why do I prefer mingw-gcc? I want to use a compiler under windows which is compatible to many other platforms. Moreover, I am using the Rcpp framework (http://dirk.eddelbuettel.com/code/rcpp.html) to integrate c/c++ code with R using the gnu/gcc toolchain.
BTW, this is how I compiled under Linux and Windows:
# Linux
egerm@bert:~/fuzzylite-5.0$ make
g++ -O1 -Wall -Isources/fuzzylite -c -o "main.o" "main.cpp"
g++ -O1 -Wall -Lsources/fuzzylite/release/bin -o main main.o -lfuzzylite
# Windows:
D:\Fuzzy\fuzzylite-5.0>make
g++ -O1 -Wall -Isources/fuzzylite -c -o "main.o" "main.cpp"
g++ -O1 -Wall -Lsources/fuzzylite/release/bin -o main main.o -lfuzzylite
The main.cpp is identical to the code here: http://fuzzylite.com/cpp
In both cases the makefile looks like this:
PRG := main
INC_DIR := -Isources/fuzzylite
LIB_DIR := -Lsources/fuzzylite/release/bin
LIBS := -lfuzzylite
CXX := g++
CXXFLAGS := -O1 -Wall
.PHONY: all
all: $(PRG)
$(PRG): main.o
$(CXX) $(CXXFLAGS) $(LIB_DIR) -o $(PRG) main.o $(LIBS)
main.o: main.cpp
$(CXX) $(CXXFLAGS) $(INC_DIR) -c -o "$@" "$<"
Kind regards
Egus