Trouble with MinGW's gcc library search paths

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Trouble with MinGW's gcc library search paths

Adam G
I am trying to develop an application that uses the freeGLUT and GLEW libraries. However, I cannot seem to get gcc to search through the appropriate library folders for the respective compiled libraries for freeGLUT and GLEW. This might just be me being ignorant of how the development process of C++ usually goes, but I did try and alter the specs file for MinGW, so that might be involved someway.

I have tried searching through the mailing list archives using the terms "linker", "libraries", and "specs", but I wasn't able to turn up anything that seemed useful. I have also been through the MinGW HOWTO pages for changing search paths, which is why I attempted to modify the specs file.

I am using MinGW 4.8.1 with MSYS 1.0 on Windows 7 version 6.1, build 7601.

Here is a rundown of what I did.

First, I used MSYS to compile the library files for freeGLUT and GLEW. I placed them in C:\MinGW\lib. Their names are libfreeglut.a and libglew32.a. I also placed their related header files in C:\MinGW\include\GL.

I have a .cpp file with #include <GL/glew.h> and #include <GL/freeglut.h>. The file's name is test. I compiled it with g++ -c test.cpp, so the header files are able to be found by gcc's g++.

Next, I attempted to link test.cpp by using g++ -o test.exe test.cpp, but this resulted in undefined reference errors.

I tried to see what directories were being searched for libraries, so I ran gcc -print-search-dirs, which had this as part of its output.

libraries: =c:/mingw/bin/../lib/gcc/mingw32/4.8.1/;
c:/mingw/bin/../lib/gcc/;
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/lib/mingw32/4.8.1/;
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/lib/;
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../mingw32/4.8.1/;
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../

So I gathered that the library search path was missing C:\MinGW\lib. To fix this, I dumped the gcc specs, added C:/MinGW/lib to the *link_libgcc area, and placed an altered specs file it in/mingw/lib/gcc/mingw32/4.8.1, just as described in the specs customization HOWTO.

Trying to link still resulted in undefined reference errors.

I next tried g++ -o test.exe test.cpp -lfreeglut and -lglew, but this also resulted in undefined reference errors.
I also tried g++ -o test.exe test.cpp -L"C:\MinGW\lib" -lfreeglut and -lglew, but this also resulted in undefined reference errors.

At this point I gave up, since it was clear I was missing something very critical in how C++ programs are compiled and linked, or in how MinGW's gcc searches for libraries, and I would not be able to find an answer quickly on my own.

Thank you very much for taking the time to read through my whingeing.

- Grupa

------------------------------------------------------------------------------
Want fast and easy access to all the code in your enterprise? Index and
search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: Trouble with MinGW's gcc library search paths

Keith Marshall
On 08/08/14 22:01, Adam G wrote:
> I am trying to develop an application that uses the freeGLUT and GLEW
> libraries ...
>
> I have a .cpp file with #include <GL/glew.h> and #include <GL/freeglut.h>.
> The file's name is test. I compiled it with g++ -c test.cpp, so the header
> files are able to be found by gcc's g++.

Presumably it compiled okay?  If so, then so far, so good.

> Next, I attempted to link test.cpp by using g++ -o test.exe test.cpp, but
> this resulted in undefined reference errors.

You neglected to tell the linker to use -lglew and -lfreeglut

> I tried to see what directories were being searched for libraries, so I ran
> gcc -print-search-dirs, which had this as part of its output.
>
> libraries: =c:/mingw/bin/../lib/gcc/mingw32/4.8.1/;
> c:/mingw/bin/../lib/gcc/;
> c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/lib/mingw32/4.8.1/;
> c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/lib/;
> c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../mingw32/4.8.1/;
> c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../
>
> So I gathered that the library search path was missing C:\MinGW\lib.

Nope. Look again. What do you get, if you canonicalize the last line?

> To fix this, I dumped the gcc specs, added C:/MinGW/lib to the
> *link_libgcc area, and placed an altered specs file it in
> /mingw/lib/gcc/mingw32/4.8.1, just as described in the specs
> customization HOWTO.

You didn't need to do this.

> Trying to link still resulted in undefined reference errors.
>
> I next tried g++ -o test.exe test.cpp -lfreeglut and -lglew, but this also
> resulted in undefined reference errors.
> I also tried g++ -o test.exe test.cpp -L"C:\MinGW\lib" -lfreeglut and
> -lglew, but this also resulted in undefined reference errors.

Are you sure you are specifying the libraries in the correct order? As
has been stated here, a gadzillion times before, this is crucial.

--
Regards,
Keith.

------------------------------------------------------------------------------
Want fast and easy access to all the code in your enterprise? Index and
search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: Trouble with MinGW's gcc library search paths

Adam G

On Fri, Aug 8, 2014 at 4:26 PM, Keith Marshall <[hidden email]> wrote:

>Nope. Look again. What do you get, if you canonicalize the last line?

I knew part of the problem was going to be something silly like this. I was interpreting the .. in the paths as a part of the path that had been compressed down or hidden, rather than correctly interpreting .. as the parent directory path.

>Are you sure you are specifying the libraries in the correct order? As
>has been stated here, a gadzillion times before, this is crucial.

This too was part of the problem. I needed to place -lglew32 before -lfreeglut. In addition, I also needed to include -lopengl32. After all of this, I was able to successfully compile, link, and run an example program that used both libraries!

I'm terribly sorry I ended up asking a question that just boiled down to me being ignorant about path canonicalization and gcc library link orders. This experience has been very instructive.

Thank you for your help Keith!

-Grupa


On Fri, Aug 8, 2014 at 4:26 PM, Keith Marshall <[hidden email]> wrote:
On 08/08/14 22:01, Adam G wrote:
> I am trying to develop an application that uses the freeGLUT and GLEW
> libraries ...
>
> I have a .cpp file with #include <GL/glew.h> and #include <GL/freeglut.h>.
> The file's name is test. I compiled it with g++ -c test.cpp, so the header
> files are able to be found by gcc's g++.

Presumably it compiled okay?  If so, then so far, so good.

> Next, I attempted to link test.cpp by using g++ -o test.exe test.cpp, but
> this resulted in undefined reference errors.

You neglected to tell the linker to use -lglew and -lfreeglut

> I tried to see what directories were being searched for libraries, so I ran
> gcc -print-search-dirs, which had this as part of its output.
>
> libraries: =c:/mingw/bin/../lib/gcc/mingw32/4.8.1/;
> c:/mingw/bin/../lib/gcc/;
> c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/lib/mingw32/4.8.1/;
> c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/lib/;
> c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../mingw32/4.8.1/;
> c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../
>
> So I gathered that the library search path was missing C:\MinGW\lib.

Nope. Look again. What do you get, if you canonicalize the last line?

> To fix this, I dumped the gcc specs, added C:/MinGW/lib to the
> *link_libgcc area, and placed an altered specs file it in
> /mingw/lib/gcc/mingw32/4.8.1, just as described in the specs
> customization HOWTO.

You didn't need to do this.

> Trying to link still resulted in undefined reference errors.
>
> I next tried g++ -o test.exe test.cpp -lfreeglut and -lglew, but this also
> resulted in undefined reference errors.
> I also tried g++ -o test.exe test.cpp -L"C:\MinGW\lib" -lfreeglut and
> -lglew, but this also resulted in undefined reference errors.

Are you sure you are specifying the libraries in the correct order? As
has been stated here, a gadzillion times before, this is crucial.

--
Regards,
Keith.

------------------------------------------------------------------------------
Want fast and easy access to all the code in your enterprise? Index and
search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:[hidden email]?subject=unsubscribe


------------------------------------------------------------------------------

_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: Trouble with MinGW's gcc library search paths

Keith Marshall
On 09/08/14 07:41, Adam G wrote:
> I'm terribly sorry I ended up asking a question that just boiled down to me
> being ignorant about path canonicalization and gcc library link orders.
> This experience has been very instructive.

There's no need to apologize.  We all start out from a state of
ignorance, then through inquiry, we convert that to knowledge.

> Thank you for your help Keith!

You're welcome.  Glad you found the solution.

--
Regards,
Keith.

------------------------------------------------------------------------------
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:[hidden email]?subject=unsubscribe