NetBeans C++: Linker Can't Find External Libraries Specified in Linker Options - c++

I've been trying to learn how to use NetBeans as a C++ development environment. I installed NetBeans 8.2, installed MinGW, and compiled a simple Hello World program to make sure everything works. I then decided to try to compiler an old OpenGL project (based on this tutorial) that I had up-and-running in Visual Studio. Unfortunately, I keep getting errors saying the linker can't find the glew32 or glut32 library files:
c:/mingw/bin/../lib/gcc/mingw32/5.3.0/../../../../mingw32/bin/ld.exe: cannot find -lglew32
c:/mingw/bin/../lib/gcc/mingw32/5.3.0/../../../../mingw32/bin/ld.exe: cannot find -lglut32
As best as I can tell, however, I've set all of the necessary linker options;
screen-shot here.
What am I missing here?
My project's compile command as stated in the output pane:
g++ -o dist/Debug/MinGW32-Windows/opengl_tutorial build/Debug/MinGW32-Windows/nbproject/Main.o build/Debug/MinGW32-Windows/nbproject/ReadTGA.o -L\"C\:/C++\ Libraries/glew-1.13.0/lib/Release/Win32\" -L\"C\:/MinGW/lib\" -L\"C\:/C++\ Libraries/glut-3.7/lib\" -lglew32 -lglut32 -lglu32 -lopengl32
Things I've Tried
Removing spaces from external libraries' file path.
Placing .lib files in MinGW's lib folder (this gets rid of the original error and results in a slew of undefined reference errors).
Adding each library's bin folder to the Aditional Library Directories list and adding the DLLs to the Libraries list.
Switching between putting the file paths in the Aditional Library Directories list in quotes and not putting them in quotes (without quotes I get undefined reference errors).
Additional System Information
Operating System: Windows 7 Home Premium 64-bit SP1
Processor: 2GHz Intel Pentium Dual-Core

Try Adding environmental variables in
Properties->Run->Environment
In my case
Name=LD_LIBRARY_PATH
Value=/usr/local/apps/Java/jdk-14/lib:/usr/local/apps/root6.22.02Install/lib/root:/Work/Soft/general_classes/lib (and some more paths which no need to be pasted here)

Related

exe can not start without codeblocks [duplicate]

I'm using the <XZY> IDE to compile my program, and have some trouble to import/integrate a specific library with it.
I get error messages like
fatal error: 3rdPartyLib.h: No such file or directory
for a
#include "3rdPartyLib.h"
statement
ld.exe: cannot find `lib3rdParty.a`
for specifying
3rdParty
in the additional libraries
At least I got some error message like
undefined reference to `lib3rdParty::foo()'
What can I do to fix this?
It's a common misconception, that the current IDE used, is responsible for getting errors like stated in the question.
See for example
c++ lib in two same project ,one can work but the other can 't
Issue linking libxml++ and glib libraries with CodeBlocks IDE for C++ Windows
...
The problem is almost never related to the currently used IDE.
In the most cases the solution boils down, to supply the actual toolchain's compiler/linker with the appropriate path's to search for included headers, to be linked libraries.
One of the major applicable answers for the linker related problems are
What is an undefined reference/unresolved external symbol error and how do I fix it?
undefined reference to `WinMain#16'
Most of the common IDEs provide features to configure this for a specific project. Here are some samples
Eclipse-CDT
Include path settings:
Library & library search path settings
Visual Studio 2013
Code Blocks
**DEV C++ (Bloodshed C++)
As from their FAQ:
9. How can i use the OpenGL library and others ?
All the libraries that comes with Mingw reside in the Lib directory. They are all named in the following way: lib*.a
To link a library with your project, just add in Project options, Further option files :
-lopengl32
This is for including the libopengl32.a library. To add any other library, just follow the same syntax:
Type -l (L in lowercase) plus the base name of the library (filename without lib and the .a extension).
You may also consider putting a -L option there to add directory pathes searched for libraries.
Qt Creator
In order to add include paths you have to open up the .pro file and then add
the directories to the INCLUDEPATH variable. These paths are separated by spaces. Reference can be found here.
If none of the above samples applies for your actually used IDE/toolchain, I hope you're able to get the point of abstraction:
It's an issue how to provide compiling/linking options to your actual toolchain. The IDE used to setup the context is a minor point here.
For eclipse I use the pkg-config plugin where possible:
https://marketplace.eclipse.org/content/pkg-config-support-eclipse-cdt
Failing that this configuration window:

Eclipse CDT project configuration [duplicate]

I'm using the <XZY> IDE to compile my program, and have some trouble to import/integrate a specific library with it.
I get error messages like
fatal error: 3rdPartyLib.h: No such file or directory
for a
#include "3rdPartyLib.h"
statement
ld.exe: cannot find `lib3rdParty.a`
for specifying
3rdParty
in the additional libraries
At least I got some error message like
undefined reference to `lib3rdParty::foo()'
What can I do to fix this?
It's a common misconception, that the current IDE used, is responsible for getting errors like stated in the question.
See for example
c++ lib in two same project ,one can work but the other can 't
Issue linking libxml++ and glib libraries with CodeBlocks IDE for C++ Windows
...
The problem is almost never related to the currently used IDE.
In the most cases the solution boils down, to supply the actual toolchain's compiler/linker with the appropriate path's to search for included headers, to be linked libraries.
One of the major applicable answers for the linker related problems are
What is an undefined reference/unresolved external symbol error and how do I fix it?
undefined reference to `WinMain#16'
Most of the common IDEs provide features to configure this for a specific project. Here are some samples
Eclipse-CDT
Include path settings:
Library & library search path settings
Visual Studio 2013
Code Blocks
**DEV C++ (Bloodshed C++)
As from their FAQ:
9. How can i use the OpenGL library and others ?
All the libraries that comes with Mingw reside in the Lib directory. They are all named in the following way: lib*.a
To link a library with your project, just add in Project options, Further option files :
-lopengl32
This is for including the libopengl32.a library. To add any other library, just follow the same syntax:
Type -l (L in lowercase) plus the base name of the library (filename without lib and the .a extension).
You may also consider putting a -L option there to add directory pathes searched for libraries.
Qt Creator
In order to add include paths you have to open up the .pro file and then add
the directories to the INCLUDEPATH variable. These paths are separated by spaces. Reference can be found here.
If none of the above samples applies for your actually used IDE/toolchain, I hope you're able to get the point of abstraction:
It's an issue how to provide compiling/linking options to your actual toolchain. The IDE used to setup the context is a minor point here.
For eclipse I use the pkg-config plugin where possible:
https://marketplace.eclipse.org/content/pkg-config-support-eclipse-cdt
Failing that this configuration window:

OpenGL codeblocks compilation issue win7 [duplicate]

I'm using the <XZY> IDE to compile my program, and have some trouble to import/integrate a specific library with it.
I get error messages like
fatal error: 3rdPartyLib.h: No such file or directory
for a
#include "3rdPartyLib.h"
statement
ld.exe: cannot find `lib3rdParty.a`
for specifying
3rdParty
in the additional libraries
At least I got some error message like
undefined reference to `lib3rdParty::foo()'
What can I do to fix this?
It's a common misconception, that the current IDE used, is responsible for getting errors like stated in the question.
See for example
c++ lib in two same project ,one can work but the other can 't
Issue linking libxml++ and glib libraries with CodeBlocks IDE for C++ Windows
...
The problem is almost never related to the currently used IDE.
In the most cases the solution boils down, to supply the actual toolchain's compiler/linker with the appropriate path's to search for included headers, to be linked libraries.
One of the major applicable answers for the linker related problems are
What is an undefined reference/unresolved external symbol error and how do I fix it?
undefined reference to `WinMain#16'
Most of the common IDEs provide features to configure this for a specific project. Here are some samples
Eclipse-CDT
Include path settings:
Library & library search path settings
Visual Studio 2013
Code Blocks
**DEV C++ (Bloodshed C++)
As from their FAQ:
9. How can i use the OpenGL library and others ?
All the libraries that comes with Mingw reside in the Lib directory. They are all named in the following way: lib*.a
To link a library with your project, just add in Project options, Further option files :
-lopengl32
This is for including the libopengl32.a library. To add any other library, just follow the same syntax:
Type -l (L in lowercase) plus the base name of the library (filename without lib and the .a extension).
You may also consider putting a -L option there to add directory pathes searched for libraries.
Qt Creator
In order to add include paths you have to open up the .pro file and then add
the directories to the INCLUDEPATH variable. These paths are separated by spaces. Reference can be found here.
If none of the above samples applies for your actually used IDE/toolchain, I hope you're able to get the point of abstraction:
It's an issue how to provide compiling/linking options to your actual toolchain. The IDE used to setup the context is a minor point here.
For eclipse I use the pkg-config plugin where possible:
https://marketplace.eclipse.org/content/pkg-config-support-eclipse-cdt
Failing that this configuration window:

How to configure Boost with Netbeans 6.9 on Ubuntu

I have gcc 4.4.5 and the latest boost library. I want to use boost specifically for its regex library. I tried using the built in c++ regex functions but apparently they are not fully functional yet. I followed a tutorial online to set up netbeans.
I added /usr/include/boost to the c++ code assistance include directories. I then added -lboost_regex-mt to the build>linker>additional options area in the project configuration. but I still get this error:
/usr/bin/ld: cannot find -lboost_regex-mt
collect2: ld returned 1 exit status
This is the command thats being created by netbeans:
g++ -lboost_regex-mt -o dist/Debug/GNU-Linux-x86/examples01 build/Debug/GNU-Linux-x86/main.o
I also tried doing it with -lboost-regex and -lboost-regex-st and the same error, with only the mt changed.
I also tried running a file using regex objects through the terminal but still got the same error. Can anyone help with this problem? Or at least point me in the right direction?
You have to set your project's "Additional Library Directories" so that it knows what other directories to look into for your libraries to link against.
Here's a screenshot from Netbeans' site here: http://netbeans.org/community/magazine/html/03/c++/
edit: note that this will affect the generated compiler command to have -L options which specify additional locations to look for library files.
You need to tell g++ where to find the libraries. One way doing this is to append the location of boost's libraries to your LD_LIBRARY_PATH. Note that this is not the same as the header files (the .hpp files in the include directory) which you said you've already included in your project.

Linking Libraries in Xcode

I'm using a powerbook (osx 10.5) and recently downloaded and installed FFTW 3.2 (link text). I've been able to compile and run some simple programs based on the online tutorial using the terminal:
g++ main.cpp -lfftw3 -lm
However, I can't get the same program to compile in Xcode. I get a linking error, "symbol(s) not found". There is a file called libfftw3.a in /usr/local/lib. How can this be linked? Furthermore, apparently the libraries have to be linked in a particular order, i.e. see: link text
thanks for any help
To link to a .a library like this in Xcode you need to:
Double-click on your target or application in Xcode to open the Info window
Switch to the "Build" tab
Add -lfftw3 to "Other Linker Flags" (under "Linking")
Add the path to your library to the "Library Search Paths" (under "Search Paths"). In your case this will be /usr/local/lib
We use FFTW (it's great by the way), this works for us!
Did you set these options for the target?
Under "Linking->Other Linker Flags" add: "-L/path/to/library -lfftw3 -lm"
warning in /Developer/SDKs/MacOSX10.5.sdk/usr/local/lib/libfftw3.a, file is not of required architecture
Maybe the binary format was different e.g. the library could be 32 bit while the application 64.
OK - I finally got this working. I also needed the the GNU Scientific Libraries and ran into similar issues with the architecture setting. For anyone interested, this tutorial goes through how to set up Xcode and link libraries:
https://web.archive.org/web/20101006023300/http://www.boyfarrell.com/learning-curve/gnu-scientific-library-and-xcode-31