Qt - Glut32 Lib - c++

I'm trying to create an Glut window with Qt creator. All my code has been done on another computer. Now, I want to compile it on my own.
I've added the Glut32 library files in the following folders:
glut32.lib into a lib/ foler in my project directory
glut32.dll into my project directory
glut.h into a GL/ folder in my project directory
In my pro files, I've added the following lines:
LIBS += -L$$PWD/lib/glut32.lib
LIBS += Opengl32.lib
And in my code, I've the following includes:
#include <gl/GL.h>
#include "GL/glut.h"
Qt does not report any error with the last include!
So, when I try to compile my code, I've many errors which say:
error LNK2019: unresolved external symbol
All those errors belongs to glut functions which cannot be found. So, did I do something wrong when I included the glut32 library?
Thanks.

Maybe it helps you to know, that you can output messages in your pro file, eg: message("Location of glut32.lib" + $$PWD/lib/glut32.lib). So you could check, whether your path is ok. Also note, that you add libraries with -l<LibName> and library paths with -L<LibPath>, so you should try to replace -L$$PWD/lib/glut32.lib by -l$$PWD/lib/glut32.lib
For further options refer to the qmake variable reference

Related

Qt linker error LNK2019 on qInitResources() - RCC

I want to compile a project with Qt in Visual Studio 2010.
I have built all the prerequisite libraries and linked them in project properties.
I have also made the .cpp file from the project.qrc file (rcc) with the command below:
rcc project.qrc -name project -o qrc_project.cpp
Followed the instructions from http://www.qtcentre.org/archive/index.php/t-3425.html .
The project.coo file is produced with the following lines:
int QT_MANGLE_NAMESPACE(qInitResources_project)()
{
QT_PREPEND_NAMESPACE(qRegisterResourceData)
(0x01, qt_resource_struct, qt_resource_name, qt_resource_data);
return 1;
}
Q_CONSTRUCTOR_FUNCTION(QT_MANGLE_NAMESPACE(qInitResources_project))
I have also included the .cpp file in the project.
Although, I get the error below:
> Error 2611 error LNK2019: unresolved external symbol "int __cdecl
> qInitResources_project(void)" (?qInitResources_project##YAHXZ)
> referenced in function main D:\usr\Windows\main.obj project
Have I done something wrong with the rcc? Could anyone please help?
I solved my problem by producing a .rcc file and a .cpp file, both with the name of the project and not with the "qrc_" at the beginning of it. I have also linked both files on my project.
It seems that the compiler could not find the proper file, this is why i had the linking error.
The commands I used in order to produce the files mentioned above are:
rcc -binary <path_to_qrc_file>.qrc -o <path_and_filename>.rcc
rcc <path_to_qrc_file>.qrc -name <project_name> -o <path_and_filename>.cpp
For someone using CMake:
you should enable AUTORCC to auto compile *.qrc files.
add_executable(project project.cpp project.qrc)
// enable autorcc and automoc
set_target_properties(project PROPERTIES AUTOMOC TRUE)
set_target_properties(project PROPERTIES AUTORCC TRUE)
I had found a really trivial workaround if nothing on SO works for you:
In VS, you can simply put your resource(images or icons) not in the library qrc file, but directly in the main project qrc file. Then, in library project, you can refer to the images using the path in main project, and there is even no need to call QT_INIT_RESOURCE.
I think this is not a good practice, but just note down for whoever tried all the solutions online and still not working.
If your project.qrc file is in the same project than the main and the main is not in a namespace, juste add Q_INIT_RESOURCE(project); in your main.
Elsewise define a function with just Q_INIT_RESOURCE(project); in it outside of any namespace in the library you have your project.qrc file.
Call that function in your main.

Cmake: link openscenegraph to my shared library

I'm new in using CMake, and I need to link openscenegraph library to my shared library.
Part of code responsible for it looks like this:
add_library (MyLib SHARED ${${PROJECT_NAME}_sources})
target_link_libraries(MyLib ${OPENSCENEGRAPH_LIBRARIES})
Im finding osg like this:
find_package(OpenSceneGraph REQUIRED osgDB osgUtil osg osgViewer osgGA osgShadow)
include_directories(${OPENSCENEGRAPH_INCLUDE_DIRS})
add_definitions(${OPENSCENEGRAPH_DEFINITIONS})
And everything looks like it is linking, CMake isn't giving me any errors, but during building with Visual Studio 2010 I got errors like:
fatal error C1083: Cannot open include file: 'osg/Node': No such file or directory
Usually I was finding answers to all my questions without asking them (this is my first question here).
This may be trivial, but can someone tell me what am I doing wrong, and how can I make it work?
This doesn't seems related to linking, but to compile. The error says that MSVC doesn't find the file 'osg/Node' in the list of included directories.
Somewhere in your source code, you probably have an include like
#include "osg/Node"
so compiler will search for a file called 'Node' in the directory called 'osg' in one of the 'include directories'.
In CMake, print the list of include dirs for OpenSceneGraph (after find_package(OpenSceneGraph ...)
message(STATUS "OSG Incl dirs: ${OPENSCENEGRAPH_INCLUDE_DIRS}")
then check this list. If it contains something like C:/path/to/openscenegraph/include then you should import Node using
#include "osg/Node"
If instead you have a folder for each module (ex: C:/path/to/openscenegraph/include/osg) so you must use
#include "Node"
If you don't want to modify includes in your code, then you have to add C:/path/to/openscenegraph/include in your include directories (from CMake script)
include_directories(C:/path/to/openscenegraph/include)

YAML-CPP with QTcreator

i try to use yaml-cpp in cmake with windows 7
I followed the tutorial and build the cmake and get yaml-cpp.dll , yaml-cpp.lib , yaml-cpp.exp
i saved them inside the libs directory in my project.
with
LIBS += -L$$PWD/libs -lyaml-cpp
i add in in my pro file. The include files are added with
INCLUDEPATH +=$$PWD\includes
inside this is my yaml-cpp directory with all include files.
On my program I use
#include <yaml-cpp/yaml.h>
This all is compiling without an error. But when I add
YAML::Node doc;
i get the undefiened reference to Yaml::Node ERROR
i dont know what i have forgot to link.
Do you have an idea? thank you for help

Using a Third Party Library Consisting of ".h", ".lib" and ".dll" Files

So currently I'm trying to use the VISA library from National Intruments and the IVI Foundation to read/write commands to various external devices.
I am relatively novice with my IDE: Microsoft Visual C++ Express 2010 and this is my first time trying to use a third party library that requires more than a .h import.
Basically I have a directory with 3 header files, a directory with 3 .lib libraries and a directory with 7 DLLs. They have no documentation as to what any of the individual files do, only the library as a whole. So, I need to be able to get all of these files associated with my project.
Currently I have all the headers imported in my header file and the header directory added to the include directories in the project properties. I also have the directory containing the .lib files added to the library directories in the project properties. I assumed that .lib files would link to the DLLs, but apparently that is not the case because I'm getting the error:
VISA Console 2.obj : error LNK2019: unresolved external symbol _viOpenDefaultRM#4 referenced in function _wmain
This error occurs when using any function from the library. Here is my code currently:
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
ViStatus status;
ViSession defaultRM, instr;
status = viOpenDefaultRM(&defaultRM);
return 0;
}
The project will build when I comment out the viOpenDefaultRM command, so I assume that means I can use the objects from the library and not the commands. Since I have the 3 object declarations that build just fine.
Okay this is all my information, hopefully someone can help and hope this helps someone else!
In addition to having the directory for the .lib file(s) added to the library directories property, you need to also add the actual libraries that the linker should search.
Add the libraries to the project's
Configuration Properties | Linker | Input | Additional Dependencies
field.
The DLLs are not necessary for the build process, but to run the program they should be in a directory inthe PATH or in the same directory as the program file.
Have you added to the project properties the additional dependecies?
Under "Linker->Input" find "Additional Dependecies" and place there the libs that you got from

unable to link FMOD library to VS2010 project

I am trying to link FMOD to my project, which I did very easily in the past in Visual Studio 2008.... So I have placed the fmodex_vc.lib and the fmodex.dll file in my project directory, added them to my project's solution explorer, then created a SoundMgr.h file which includes the fmod.h file
#include "include\fmod\fmod.h"
Where fmod has been placed in the include\fmod folder and opens ok if i right click on the above code and click "Open Document"...
But if I try to write any code at all, including a simple "using namespace FMOD" it tells me that it FMOD is undeclared or unidentified.... am I missing any step?
EDIT:
What the class looks like so far is:
#pragma once
#include "main.h"
#include "include\fmod\fmod.hpp"
#include "include\fmod\fmod_errors.h"
#include "include\fmod\fmod.h"
class SoundMgr{
void init();
};
void SoundMgr::init(){
FSOUND_Init (44100, 32, 0);
}
And the error is:
Error 1 error C3861: 'FSOUND_Init': identifier not found
And that's for any line of the sample code that I try import from this quick guide:
GameDev FMOD quick guide
I tried adding the library as an additional dependency in the Input section of the Properties/Linker and I get
1. fatal error LNK1181: cannot open input file 'fmodex_vc.lib'
Any of these errors ring a bell?
Don't you want fmod.hpp to get the c++ features?
you can include the headers path in C/C++ > General and library path to Linker properties and include the dll's in you project. In this case you have the files in you release/debug dir
Right so I eventually fixed it by removing the Additional Dependency in the Input section of the Linker and instead adding Include and Library directories in in Configuration Properties\VC++ directories.... Most articles I found advise to use the actual full path to the FMOD installation folder, but since I want this project to be portable and self contained, i created a "lib" and "include" folder in my project and put those files in them... (used the directories "\lib" and "\include" in the project properties which I am assuming links to the project folder, have never done this before but am hoping it won't cause dependency issues if I compile this on a different machine)...