I am learning about OpenGL and am having great difficulty opening a file with openGL. This is what my reference says to do:
"Compile and run the program
To compile the sample program, you need to link to the OpenGL and freeglut libraries. You will also need the GLEW library to be able to use many OpenGL functions, including shaders.
The exact names of these libraries vary from system to system, for example:
Linux
: libGL.a, libglut.a
Compile with
g++ main.cpp -lGL -lglut -lGLE"
I have run this code in my linux terminal (I'm using Redhat) and I get a whole bunch of errors about not being able to locate the files
[a1649446#ingb24w027 code]$ g++ main.cpp -lGL -lglut -lGLEW
main.cpp:46:23: error: glm/glm.hpp: No such file or directory
main.cpp:47:40: error: glm/gtc/matrix_transform.hpp: No such file or directory
main.cpp:48:32: error: glm/gtc/type_ptr.hpp: No such file or directory
main.cpp:62: error: ‘glm’ has not been declared
main.cpp:62: error: expected constructor, destructor, or type conversion before ‘cameraMatrix’
main.cpp: In function ‘int setShaderData(const unsigned int&)’:
main.cpp:102: error: ‘glm’ has not been declared
main.cpp:102: error: expected ‘;’ before ‘projection’
main.cpp:105: error: ‘glm’ has not been declared
main.cpp:105: error: ‘projection’ was not declared in this scope
main.cpp:109: error: ‘glm’ has not been declared
main.cpp:109: error: expected ‘;’ before ‘modelview’
main.cpp: In function ‘void render()’:
main.cpp:187: error: ‘cameraMatrix’ was not declared in this scope
main.cpp:187: error: ‘glm’ has not been declared
main.cpp:200: error: ‘glm’ has not been declared
I'm sure the answer is painfully obvious, but I am an OpenGL noob. I have even located all the openGL libraries and copy-pasted them into the folder with my main.cpp and all associated files, to no avail.
Related
I'm currently working on a project which executes correctly using an arduino library (VirtualWire), yet would like to move away from Arduino and back into pure C/C++.
I could:
- rewrite the actual arduino functions
- rewrite the calls to arduino functions (change pinmode to DDRx, etc)
- use the arduino core source code in conjunction with the library.
I have already attempted the last point, moving the relevent arduino source code in with the virtual wire library, however when i try to compile- i cant link against the VirtualWire library.
NOTE: the VirtualWire library and its dependencies (hopefully) is located in the same directory as my source code (as a test).
Using the following compile command, i achieve the following errors:
avr-g++ -mmcu=atmega32u4 -Os -DF_CPU=8000000UL -IVirtualWire -LVirtualWire -lVirtualWire transmitter.cpp -o transmitter.o
c:/winavr-20100110/bin/../lib/gcc/avr/4.3.3/../../../../avr/bin/ld.exe: cannot find -lVirtualWire
Or alternatively,
avr-g++ -mmcu=atmega32u4 -Os -DF_CPU=8000000UL -IVirtualWire -LVirtualWire transmitter.cpp -o transmitter.o
C:\cygwin\tmp/cc8d5ab7.o: In function `setup':
transmitter.cpp:(.text+0xe): undefined reference to `vw_set_tx_pin'
transmitter.cpp:(.text+0x14): undefined reference to `vw_set_rx_pin'
transmitter.cpp:(.text+0x1a): undefined reference to `vw_set_ptt_pin'
transmitter.cpp:(.text+0x20): undefined reference to `vw_set_ptt_inverted'
transmitter.cpp:(.text+0x28): undefined reference to `vw_setup'
C:\cygwin\tmp/cc8d5ab7.o: In function `main':
transmitter.cpp:(.text+0x6e): undefined reference to `vw_send'
transmitter.cpp:(.text+0x72): undefined reference to `vw_wait_tx'
transmitter.cpp:(.text+0x80): undefined reference to `delay'
And lastly,
avr-g++ -mmcu=atmega32u4 -Os -DF_CPU=8000000UL transmitter.cpp -o transmitter.o
transmitter.cpp:1:25: error: VirtualWire.h: No such file or directory
transmitter.cpp: In function 'int main()':
transmitter.cpp:26: error: 'HIGH' was not declared in this scope
transmitter.cpp:26: error: 'digitalWrite' was not declared in this scope
transmitter.cpp:27: error: 'uint8_t' was not declared in this scope
transmitter.cpp:27: error: expected primary-expression before ')' token
transmitter.cpp:27: error: 'vw_send' was not declared in this scope
transmitter.cpp:28: error: 'vw_wait_tx' was not declared in this scope
transmitter.cpp:29: error: 'LOW' was not declared in this scope
transmitter.cpp:30: error: 'delay' was not declared in this scope
transmitter.cpp: In function 'void setup()':
transmitter.cpp:42: error: 'CLKPR' was not declared in this scope
transmitter.cpp:44: error: 'vw_set_tx_pin' was not declared in this scope
transmitter.cpp:45: error: 'vw_set_rx_pin' was not declared in this scope
transmitter.cpp:46: error: 'vw_set_ptt_pin' was not declared in this scope
transmitter.cpp:47: error: 'vw_set_ptt_inverted' was not declared in this scope
transmitter.cpp:48: error: 'vw_setup' was not declared in this scope
transmitter.cpp:49: error: 'OUTPUT' was not declared in this scope
transmitter.cpp:49: error: 'pinMode' was not declared in this scope
I am familiar with C/C++, however only today did i find out there were different types of libraries.
Is there something obvious i am doing wrong, or an easier way to transfer this library from Arduino to pure C/C++?
Thanks in advance!
I do not have permissions to put GLM into usr/local/include or usr/include but I need to use GLM for openGL. The code (I am not able to change) looks for GLM like this:
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
the folder glm is in the same directory as my main.cpp where this code is from. I think it's not working because it's looking for glm in usr/include where in built headers are (im using redhat linux)
How can I stop this from happening, since I cannot run:
g++ main.cpp -lGL -lglut -lGLEW
without these errors:
main.cpp:46:23: error: glm/glm.hpp: No such file or directory
main.cpp:47:40: error: glm/gtc/matrix_transform.hpp: No such file or directory
main.cpp:48:32: error: glm/gtc/type_ptr.hpp: No such file or directory
main.cpp:62: error: ‘glm’ has not been declared
main.cpp:62: error: expected constructor, destructor, or type conversion before ‘cameraMatrix’
main.cpp: In function ‘int setShaderData(const unsigned int&)’:
main.cpp:102: error: ‘glm’ has not been declared
main.cpp:102: error: expected ‘;’ before ‘projection’
main.cpp:105: error: ‘glm’ has not been declared
main.cpp:105: error: ‘projection’ was not declared in this scope
main.cpp:109: error: ‘glm’ has not been declared
main.cpp:109: error: expected ‘;’ before ‘modelview’
main.cpp: In function ‘void render()’:
main.cpp:187: error: ‘cameraMatrix’ was not declared in this scope
main.cpp:187: error: ‘glm’ has not been declared
main.cpp:200: error: ‘glm’ has not been declared
My answer isn't really related to the author's question, but I'm just leaving it here for those, who come here from ubuntu with a missing package
sudo apt-get install libglm-dev
GLM is not part of OpenGL. It's a C++ math library that has much of the same syntax as GLSL. In order to use it you need to download it from here or install it using your package manager (although if you don't have administrative rights on this machine, then you won't be able to do that).
Once you have it, you need to add it to your include path:
g++ main.cpp -lGL -lglut -lGLEW -I/path/to/glm/headers
Although if you install it with a package manager it will probably end up in your system include path.
I've just installed a clean vm with xubuntu 12.10 and I'm trying to port over some C++ code which works perfectly on Windows. First off, I've installed Virtualbox guest additions and GCC and I can compile code.
I've downloaded the boost library from the internet (boost_1_52) and I've dropped in the asio library from the asio website (boost_asio_1_4_8) and I've installed the multi-threading, shared link version using these instructions:
./bootstrap.sh --prefix=/usr &&
./b2 stage threading=multi link=shared
as root:
I know for a fact that boost works because I've been able to compile the test application here (linking with lboost_regex) and it works perfectly:
#include <boost/regex.hpp>
#include <iostream>
#include <string>
int main()
{
std::string line;
boost::regex pat( "^Subject: (Re: |Aw: )*(.*)" );
while (std::cin)
{
std::getline(std::cin, line);
boost::smatch matches;
if (boost::regex_match(line, matches, pat))
std::cout << matches[2] << std::endl;
}
}
So I'm trying to build one of the ASIO examples, which I've built before with no problems on Windows. The files are here:
http://www.boost.org/doc/libs/1_53_0/doc/html/boost_asio/examples.html
See:
boost_asio/example/serialization/client.cpp
boost_asio/example/serialization/connection.hpp
boost_asio/example/serialization/server.cpp
boost_asio/example/serialization/stock.hpp
I throw my compiler this:
gcc client.cpp -I /usr/include/boost -lboost_system -lboost_thread -lboost_serialization
Which gives me this error:
connection.hpp:75:35: error: template argument 1 is invalid
connection.hpp:75:35: error: template argument 2 is invalid
connection.hpp:75:44: error: invalid type in declaration before ‘;’ token
connection.hpp:76:13: error: request for member ‘push_back’ in ‘buffers’, which is of non-class type ‘int’
connection.hpp:76:23: error: ‘asio’ is not a class or namespace
connection.hpp:77:13: error: request for member ‘push_back’ in ‘buffers’, which is of non-class type ‘int’
connection.hpp:77:23: error: ‘asio’ is not a class or namespace
connection.hpp:78:5: error: ‘asio’ is not a class or namespace
connection.hpp:78:23: error: ‘socket_’ was not declared in this scope
connection.hpp: In member function ‘void s11n_example::connection::async_read(T&, Handler)’:
connection.hpp:87:15: error: ‘asio’ does not name a type
connection.hpp:87:31: error: expected unqualified-id before ‘&’ token
connection.hpp:87:31: error: expected ‘)’ before ‘&’ token
connection.hpp:87:31: error: expected initializer before ‘&’ token
connection.hpp:90:5: error: ‘asio’ has not been declared
connection.hpp:90:22: error: ‘socket_’ was not declared in this scope
connection.hpp:90:31: error: ‘asio’ has not been declared
connection.hpp:91:21: error: ‘f’ was not declared in this scope
connection.hpp:92:17: error: ‘asio’ has not been declared
client.cpp: At global scope:
client.cpp:26:10: error: ‘asio’ has not been declared
client.cpp:26:26: error: expected ‘)’ before ‘&’ token
client.cpp:43:29: error: ‘asio’ does not name a type
client.cpp:43:45: error: expected unqualified-id before ‘&’ token
client.cpp:43:45: error: expected ‘)’ before ‘&’ token
client.cpp:43:35: error: expected ‘;’ at end of member declaration
client.cpp:43:47: error: ISO C++ forbids declaration of ‘e’ with no type [-fpermissive]
client.cpp:43:47: error: expected ‘;’ at end of member declaration
client.cpp:43:48: error: expected unqualified-id before ‘)’ token
client.cpp:125:1: error: expected ‘}’ at end of input
client.cpp:125:1: error: expected unqualified-id at end of input
client.cpp:125:1: error: expected ‘}’ at end of input
I'm really confused, its as if I've not built boost or I'm missing another link. I've also tried linking with Winsock, with no results. Please help!
Cheers
You are using gcc and g++ interchangeably. The line which doesn't work uses gcc, but the line which works uses g++. Using g++ instead of gcc may effect which default include path is used. Your initial error was not linking. It was compiling. Also, if you use the boost version, asio namespace is not asio. It's boost::asio.
Looks like boost/asio.hpp didn't get included correctly.
I don't remember exactly what the prefix option does, but I think your problem may be somewhere in there. The boost directory may not be in /usr/include/boost, but instead possibly /usr/boost.
That's one possibility. The second is that, instead of passing /usr/include/boost, you need to pass /usr/include, i.e.
gcc client.cpp -I /usr/include -lboost_system -lboost_thread -lboost_serialization
If you look at the example files, e.g. the connection.cpp example, it includes boost/asio.hpp. The boost/ part refers to a folder that should be looked for by the compiler in the include path(s) you specify using -I. So if you specified /usr/include/boost, the compiler is going to look for /usr/include/boost/boost/asio.hpp (notice the 2 occurrences of boost).
I think I've fixed the problem now. Using bjam and the auto-installer doesn't seem to accomplish much (it won't resolve to those paths for some reason).
Anyway, I downloaded the ASIO source code (non-boost this time) and put that in a directory on my desktop. In a similar fashion to how I do it on windows in Visual Studio, I managed to get it to link:
g++ client.cpp -I/home/devbox/desktop/asio-1.5.3/include - L/home/devbox/Desktop/boost_1_53_0/stage/lib -lboost_system -lboost_thread -lboost_serialization -o test
Cheers all
I am trying to run the sample code shown here. I built wxWidgets from source using MinGW, with this command: mingw32-make -f makefile.gcc SHARED=1 UNICODE=0 BUILD=debug. In my Eclipse settings, I add -Iwx288/include, -Lwx288/lib, -lwxbase28d_gcc_custom and -lwxmsw28d_core_gcc_custom. I get very very confused, due to the number of ways to compile and inexperience with linkers. I get these errors, what am I doing wrong? I'm not even citing wxMutex in my program.
23:15:19 **** Incremental Build of configuration Debug for project A ****
Info: Internal Builder is used for build
g++ "-IC:\\Files\\Programming\\C++\\A\\include" -O0 -g3 -Wall -c -fmessage-length=0 -o "include\\wx\\thrimpl.o" "..\\include\\wx\\thrimpl.cpp"
..\include\wx\thrimpl.cpp:18:1: error: 'wxMutex' does not name a type
..\include\wx\thrimpl.cpp:29:1: error: 'wxMutex' does not name a type
..\include\wx\thrimpl.cpp:34:6: error: 'wxMutex' has not been declared
..\include\wx\thrimpl.cpp:34:22: error: non-member function 'bool IsOk()' cannot have cv-qualifier
..\include\wx\thrimpl.cpp: In function 'bool IsOk()':
..\include\wx\thrimpl.cpp:36:12: error: 'm_internal' was not declared in this scope
..\include\wx\thrimpl.cpp:36:26: error: 'NULL' was not declared in this scope
..\include\wx\thrimpl.cpp: At global scope:
..\include\wx\thrimpl.cpp:39:1: error: 'wxMutexError' does not name a type
..\include\wx\thrimpl.cpp:47:1: error: 'wxMutexError' does not name a type
..\include\wx\thrimpl.cpp:55:1: error: 'wxMutexError' does not name a type
..\include\wx\thrimpl.cpp:224:1: error: 'wxCondition' does not name a type
..\include\wx\thrimpl.cpp:235:1: error: 'wxCondition' does not name a type
..\include\wx\thrimpl.cpp:240:6: error: 'wxCondition' has not been declared
..\include\wx\thrimpl.cpp:240:26: error: non-member function 'bool IsOk()' cannot have cv-qualifier
..\include\wx\thrimpl.cpp: In function 'bool IsOk()':
..\include\wx\thrimpl.cpp:240:6: error: redefinition of 'bool IsOk()'
..\include\wx\thrimpl.cpp:34:6: error: 'bool IsOk()' previously defined here
..\include\wx\thrimpl.cpp:242:12: error: 'm_internal' was not declared in this scope
..\include\wx\thrimpl.cpp:242:26: error: 'NULL' was not declared in this scope
..\include\wx\thrimpl.cpp: At global scope:
..\include\wx\thrimpl.cpp:245:1: error: 'wxCondError' does not name a type
..\include\wx\thrimpl.cpp:253:1: error: 'wxCondError' does not name a type
..\include\wx\thrimpl.cpp:261:1: error: 'wxCondError' does not name a type
..\include\wx\thrimpl.cpp:269:1: error: 'wxCondError' does not name a type
..\include\wx\thrimpl.cpp:281:1: error: 'wxSemaphore' does not name a type
..\include\wx\thrimpl.cpp:291:1: error: 'wxSemaphore' does not name a type
..\include\wx\thrimpl.cpp:296:6: error: 'wxSemaphore' has not been declared
..\include\wx\thrimpl.cpp:296:26: error: non-member function 'bool IsOk()' cannot have cv-qualifier
..\include\wx\thrimpl.cpp: In function 'bool IsOk()':
..\include\wx\thrimpl.cpp:296:6: error: redefinition of 'bool IsOk()'
..\include\wx\thrimpl.cpp:34:6: error: 'bool IsOk()' previously defined here
..\include\wx\thrimpl.cpp:298:12: error: 'm_internal' was not declared in this scope
..\include\wx\thrimpl.cpp:298:26: error: 'NULL' was not declared in this scope
..\include\wx\thrimpl.cpp: At global scope:
..\include\wx\thrimpl.cpp:301:1: error: 'wxSemaError' does not name a type
..\include\wx\thrimpl.cpp:309:1: error: 'wxSemaError' does not name a type
..\include\wx\thrimpl.cpp:317:1: error: 'wxSemaError' does not name a type
..\include\wx\thrimpl.cpp:325:1: error: 'wxSemaError' does not name a type
..\include\wx\thrimpl.cpp: In function 'bool IsOk()':
..\include\wx\thrimpl.cpp:299:1: warning: control reaches end of non-void function [-Wreturn-type]
..\include\wx\thrimpl.cpp: In function 'bool IsOk()':
..\include\wx\thrimpl.cpp:243:1: warning: control reaches end of non-void function [-Wreturn-type]
..\include\wx\thrimpl.cpp: In function 'bool IsOk()':
..\include\wx\thrimpl.cpp:37:1: warning: control reaches end of non-void function [-Wreturn-type]
23:15:20 Build Finished (took 657ms)
Why are you trying to compile include/wx/thrimpl.cpp? It's not your file, it's part of wxWidgets and it shouldn't be compiled as part of your project. Just remove it from the list of project files.
I'm guessing you are either missing something in your include path or some of the Defines required by wxWidgets in order to process wxWidgets Header-Files correctly
WX comes with a tool called wx-config ( should be located somewhere in wxWidgets/bin if your build was successful)
wx-config is a shell-script, you can execute it using mingw-msys
wx-config --cxxflags produces all Include Paths and Defines needed to compile object files.
wx-config --libs takes care of everything needed to link the program
I would recommend using wx-config in your makefile/builder/....
or check the output produced by it and compare it to your build process
Samples form my current installation:
$ wx-config --cxxflags --static=no --debug=yes --unicode=no -I/wx/lib/wx/include/msw-ansi-debug-2.8 -I/wx/include/wx-2.8 -D_WXDEBUG_ -DWXUSINGDLL -D_WXMSW_ -mthreads
$ ./wx-config --libs --static=no --debug=yes --unicode=no -L/wx/lib -mthreads -Wl,--subsystem,windows -mwindows -lwx_mswd_richtext-2.8 -lwx_mswd_aui-2.8 -lwx_mswd_xrc-2.8 -lwx_mswd_qa-2.8 -lwx_mswd_html-2.8 -lwx_mswd_adv-2.8 -lwx_mswd_core-2.8 -lwx_based_xml-2.8 -lwx_based_net-2.8 -lwx_based-2.8
I get the following error when compiling this third-party library (called azove 2.0) which relies on the GNU Multi-precision library:
> make
g++ -Wall -O3 -DFIX_NUMBER_OF_SIGMDDNODE_SONS -DUSE_TIMER -I. -c conBDD.cpp -o conBDD.o
In file included from conBDDnode.hpp:27,
from conBDD.hpp:25,
from conBDD.cpp:22:
/usr/include/gmpxx.h: In destructor ‘__gmp_alloc_cstring::~__gmp_alloc_cstring()’:
/usr/include/gmpxx.h:2096: error: ‘strlen’ was not declared in this scope
conBDD.cpp: In member function ‘void conBDD::build()’:
conBDD.cpp:61: error: ‘numeric_limits’ was not declared in this scope
conBDD.cpp:61: error: expected primary-expression before ‘int’
conBDD.cpp:61: error: expected `;' before ‘int’
conBDD.cpp:68: error: expected primary-expression before ‘int’
conBDD.cpp:68: error: expected `;' before ‘int’
make: *** [conBDD.o] Error 1
I have tried adding either and both of the following lines
#include <cstdlib>
using std::strlen;
to conBDD.cpp, but the error persists.
I can't tell if this is an error comes from GNU's Multi-precision library or from Azove. Any pointers would be greatly appreciated.
I would start by apportioning blame. Create an empty cpp file, say test.cpp, in your project and include only the offending gmpxx.h file. If you can compile test cpp, GMP is off the hook. Then try including only the offending azove header. If you can compile the azove header in an otherwise empty file, azove is off the hook and something you are including/defining is interfering with them. Once you have narrowed down the source of the problem you should find it easier to fix.