0

I want to write and compile C++ code that requires the FLTK 1.3.2 GUI libraries. I would like to use minGW with MSYS.
I have installed minGW and MSYS properly and have been able to build FLTK with ./configure make. Everything worked up to this point. Now I am testing the hello program, and can get the compiler to locate the header files, but it returns errors - which I believe are a result of the compiler not finding the location of the FLTK library. I have looked over the minGW site and it seems the difficulty of getting MSYS to direct the compiler to the correct location is not uncommon.

I have worked with C++ minGW for about a year but am completely new to MSYS.

Here is my command:

c++ Hello.cxx -Lc:/fltk-1.3.2/test -Ic:/fltk-1.3.2 -o Hello.exe

(I am not sure if my syntax is correct so any comments are appreciated)

Here is what I get from the compiler:

C:\Users\CROCKE~1\AppData\Local\Temp\ccbpaWGj.o:hello.cxx(.text+0x3c): undefined reference to 'Fl_Window::Fl_Window(int, int, char const*)'

... more similar comments...

collect2: ld returned exit status

It seems the compiler can't find the function definitions which I believe are in c:/fltk-1.3.2/test.

Again, I am a newbie so any help is greatly appreciated. Thanks.

nsgulliver
  • 12,655
  • 23
  • 43
  • 64

1 Answers1

0

Your compile command is not good... You only inform LD where to search for additional libraries with the -L parameter, but you do not specify any library you actually want to use. For that you use -l flag. So the command should be something like: g++ Hello.cxx -Lc:/fltk-1.3.2/test -Ic:/fltk-1.3.2 -o Hello.exe -llibfltk_images -llibfltk -llibwsock32 -llibgdi32 -llibuuid -llibole32 My recommendation - use the provided fltk-config script to obtain the flags.

Here is a MinGW makefile I "stole" from here: http://www.fltk.org/articles.php?L1286 .

# Makefile for building simple FLTK programs
# using MinGW on the windows platform.

# I recommend setting C:\MinGW\bin AND C:\MinGW\msys\1.0\bin 
# in the environment %PATH% variable on the development machine.

MINGW=C:/MinGW
MSYS=${MINGW}/msys/1.0
FLTK_CONFIG=${MSYS}/local/bin/fltk-config
INCLUDE=-I${MSYS}/local/include
LIBS=-L${MSYS}/local/lib 
CC=${MINGW}/bin/g++.exe
RM=${MSYS}/bin/rm
LS=${MSYS}/bin/ls
EXE=dynamic_buttons_scroll.exe

SRC=$(shell ${LS} *.cxx)
OBJS=$(SRC:.cxx=.o)
CFLAGS=${INCLUDE} `${FLTK_CONFIG} --cxxflags`
LINK=${LIBS} `${FLTK_CONFIG} --ldflags`

all:${OBJS}
        ${CC} ${OBJS} ${LINK} -o ${EXE}

%.o: %.cxx
        ${CC} ${INCLUDE} ${CFLAGS} -c $*.cxx -o $*.o

clean:
        - ${RM} ${EXE}
        - ${RM} ${OBJS}

tidy: all
        - ${RM} ${OBJS}

rebuild: clean all

# Remember, all indentations must be tabs... not spaces.
DejanLekic
  • 18,787
  • 4
  • 46
  • 77