# Solved: Compiling & linking in Windows - need help!



## BlackGarden (May 23, 2004)

I have a C program, which I have written in a file mandelbrot.c. I'm trying to compile and link it using gcc. In DOS, I run (from the working directory):

gcc -c mandelbrot.c -o mandelbrot.o

Which works fine. Now I need to link it, and it requires a library libmbrot.so which is in .\lib from the working directory. When I do it on the uni computers (on Linux), I just need to run export LD_LIBRARY_PATH=usr/lib:./lib then use -lmbrot, and it links fine. I now need to work on this file at home, and can't get the file to link. I've tried, among many other commands:

gcc -o mandelbrot.exe mandelbrot.o -L.\lib -lmbrot (I have also tried this command with various ways of writing the path, including the relative and full path, in DOS style and in Unix style.)

All the time when running these commands I get:
"c:/djgpp/bin/ld.exe: cannot find -lmbrot
collect2: ld returned 1 exit status"

I have also tried copying libmbrot.so to c:\djgpp\lib

I have been given the source for libmbrot.so so I could recompile that file if necessary. The source files I've been given are:

Mandelbrot.cpp
MandelbrotPanel.h
MandelbrotPanel.o
mbrot.cpp
mbrot.o

And I also have a makefile to update the library under Linux, which reads:

```
LIBS     = -L${QTDIR}/lib -lqt-mt -lGL -lGLU -lm
INCPATH  = -I${QTDIR}/include -I../incl

CFLAGS=${INCPATH}

../lib/libmbrot.so: MandelbrotPanel.o mbrot.o
	${LD} -shared MandelbrotPanel.o mbrot.o -o ../lib/libmbrot.so ${LIBS}

.c.o:
	${CC} ${CFLAGS} -c $< -o [email protected]

.cpp.o:
	${CXX} ${CFLAGS} -c $< -o [email protected]

clean:
	rm -f *.o
	rm -f *~
	rm -f ../lib/libmbrot.so
```
If anyone can help me with this I'd be really really grateful, and it would save my laptop a lot of abuse from my head. I hope I've given you enough information to help me with, but if you need to know something else so you can help me, or you want me to try something out, just ask.

EDIT: By the by, installing Linux isn't an option right now, but it will be in about a month's time, thank God. Unfortunately that doesn't really help me right now because this work needs doing before that.


----------



## lotuseclat79 (Sep 12, 2003)

Hi BlackGarden,

Welcome to TSG!

When you say that .\lib is where libmbrot.so is located relative to the working directory (in Windows), that should work out to be a subdirectory as in ./lib which is how it would be in Linux/Unix. Is that the case - just to check that .\lib is a subdirectory to the working directory path?

Also, when specifying library paths, it is best to always use the full path rather than relative paths - try converting the LD_LIBRARY_PATH from: 
LD_LIBRARY_PATH=usr/lib:./lib
to something like
LD_LIBRARY_PATH=/usr/lib:/<fullpath of working directory>/lib

-- Tom


----------



## BlackGarden (May 23, 2004)

Yes, the lib folder containing libmbrot.so is a subdirectory of the working directory path.
I've tried using the full path, but to no avail. I've decided to get a bit more drastic and install Linux now. It's about time I stopped putting it off. Thanks for the suggestion anyway 

PS If you know anything handy about formatting and repartitioning hard drives, please read my post in the XP forum


----------

