SFML VertexArray not member of sf - c++

I have the following program for drawing a triangle with vertex arrays, as described in SFML tutorials.
#include <SFML/Graphics.hpp>
#include <iostream>
int main()
{
try{
sf::RenderWindow Mywindow(sf::VideoMode(800,600),"TriColor Triangle!");
sf::VertexArray triangle(sf::Triangles, 3);
triangle[0].position = sf::Vector2f(5,5);
triangle[1].position = sf::Vector2f(50,5);
triangle[2].position = sf::Vector2f(50,50);
triangle[0].color = sf::Color::Red;
triangle[1].color = sf::Color::Blue;
triangle[2].color = sf::Color::Green;
Mywindow.draw(triangle);
}
catch( const std::runtime_error& e)
{
std::cout << e.what() << std::endl;
std::cin.ignore();
return EXIT_FAILURE;
}
std::cin.ignore();
return EXIT_SUCCESS;
}
The Makefile for compilation I am using is the following:
all: exe
exe: main.o
g++ main.o -o exe -lsfml-graphics -lsfml-window -lsfml-system
main.o: main.cpp
g++ -c main.cpp
The follwing error is being displayed:
make
g++ -c main.cpp
main.cpp: In function ‘int main()’:
main.cpp:11:2: error: ‘VertexArray’ is not a member of ‘sf’
main.cpp:11:18: error: expected ‘;’ before ‘triangle’
main.cpp:13:2: error: ‘triangle’ was not declared in this scope
main.cpp:21:11: error: ‘class sf::RenderWindow’ has no member named ‘draw’
main.cpp:23:33: error: expected unqualified-id before ‘&’ token
main.cpp:23:33: error: expected ‘)’ before ‘&’ token
main.cpp:23:33: error: expected ‘{’ before ‘&’ token
main.cpp:23:35: error: ‘e’ was not declared in this scope
main.cpp:23:36: error: expected ‘;’ before ‘)’ token
make: *** [main.o] Error 1
I don't understand why it is saying VertexArray not member of sf!

You must provide a path to the SFML lib dir and a path to the SFML include dir.
Like this:
"-IC:\\Path\\to\\your\\project\\your-lib-sub-dir\\SFML-2.1\\include"
"-LC:\\Path\\to\\your\\project\\your-lib-sub-dir\\SFML-2.1\\lib"
Another thing, to be able to see something, you should suround your draw call with something like this:
while(1){
Mywindow.clear(sf::Color::Black);
Mywindow.draw(triangle);
Mywindow.display();
}

Related

Compiling a quickfix program

I am trying to use the quickfix library to connect to a broker using the FIX protocol. I just built the library using the documentation they provide and use their sample code right now
#include "quickfix/FileStore.h"
#include "quickfix/FileLog.h"
#include "quickfix/SocketAcceptor.h"
#include "quickfix/Session.h"
#include "quickfix/SessionSettings.h"
#include "quickfix/Application.h"
int main( int argc, char** argv )
{
try
{
if(argc < 2) return 1;
std::string fileName = argv[1];
FIX::SessionSettings settings(fileName);
MyApplication application;
FIX::FileStoreFactory storeFactory(settings);
FIX::FileLogFactory logFactory(settings);
FIX::SocketAcceptor acceptor
(application, storeFactory, settings, logFactory /*optional*/);
acceptor.start();
// while( condition == true ) { do something; }
acceptor.stop();
return 0;
}
catch(FIX::ConfigError& e)
{
std::cout << e.what();
return 1;
}
}
However, when I try to compile it with:
g++ fix.cpp -fexceptions -finline-functions -lquickfix -lpthread -lxml2
I get a bunch of errors:
In file included from /usr/local/include/quickfix/Session.h:34:0,
from fix.cpp:6:
/usr/local/include/quickfix/DataDictionaryProvider.h:54:72: error: ‘ptr::shared_ptr’ has not been declared
void addTransportDataDictionary(const BeginString& beginString, ptr::shared_ptr<DataDictionary>);
^
/usr/local/include/quickfix/DataDictionaryProvider.h:54:82: error: expected ‘,’ or ‘...’ before ‘<’ token
void addTransportDataDictionary(const BeginString& beginString, ptr::shared_ptr<DataDictionary>);
^
/usr/local/include/quickfix/DataDictionaryProvider.h:55:70: error: ‘ptr::shared_ptr’ has not been declared
void addApplicationDataDictionary(const ApplVerID& applVerID, ptr::shared_ptr<DataDictionary>);
^
/usr/local/include/quickfix/DataDictionaryProvider.h:55:80: error: expected ‘,’ or ‘...’ before ‘<’ token
void addApplicationDataDictionary(const ApplVerID& applVerID, ptr::shared_ptr<DataDictionary>);
^
/usr/local/include/quickfix/DataDictionaryProvider.h:63:25: error: ‘shared_ptr’ is not a member of ‘ptr’
std::map<std::string, ptr::shared_ptr<DataDictionary> > m_transportDictionaries;
^
/usr/local/include/quickfix/DataDictionaryProvider.h:63:25: error: ‘shared_ptr’ is not a member of ‘ptr’
/usr/local/include/quickfix/DataDictionaryProvider.h:63:55: error: template argument 2 is invalid
std::map<std::string, ptr::shared_ptr<DataDictionary> > m_transportDictionaries;
^
/usr/local/include/quickfix/DataDictionaryProvider.h:63:55: error: template argument 4 is invalid
/usr/local/include/quickfix/DataDictionaryProvider.h:63:57: error: expected unqualified-id before ‘>’ token
std::map<std::string, ptr::shared_ptr<DataDictionary> > m_transportDictionaries;
^
/usr/local/include/quickfix/DataDictionaryProvider.h:64:25: error: ‘shared_ptr’ is not a member of ‘ptr’
std::map<std::string, ptr::shared_ptr<DataDictionary> > m_applicationDictionaries;
^
/usr/local/include/quickfix/DataDictionaryProvider.h:64:25: error: ‘shared_ptr’ is not a member of ‘ptr’
/usr/local/include/quickfix/DataDictionaryProvider.h:64:55: error: template argument 2 is invalid
std::map<std::string, ptr::shared_ptr<DataDictionary> > m_applicationDictionaries;
^
/usr/local/include/quickfix/DataDictionaryProvider.h:64:55: error: template argument 4 is invalid
/usr/local/include/quickfix/DataDictionaryProvider.h:64:57: error: expected unqualified-id before ‘>’ token
std::map<std::string, ptr::shared_ptr<DataDictionary> > m_applicationDictionaries;
^
/usr/local/include/quickfix/DataDictionaryProvider.h: In member function ‘void FIX::DataDictionaryProvider::addTransportDataDictionary(const FIX::BeginString&, const string&)’:
/usr/local/include/quickfix/DataDictionaryProvider.h:58:45: error: ‘shared_ptr’ is not a member of ‘ptr’
{ addTransportDataDictionary(beginString, ptr::shared_ptr<DataDictionary>( new DataDictionary(path) )); }
^
/usr/local/include/quickfix/DataDictionaryProvider.h:58:75: error: expected primary-expression before ‘>’ token
{ addTransportDataDictionary(beginString, ptr::shared_ptr<DataDictionary>( new DataDictionary(path) )); }
^
/usr/local/include/quickfix/DataDictionaryProvider.h: In member function ‘void FIX::DataDictionaryProvider::addApplicationDataDictionary(const FIX::ApplVerID&, const string&)’:
/usr/local/include/quickfix/DataDictionaryProvider.h:60:45: error: ‘shared_ptr’ is not a member of ‘ptr’
{ addApplicationDataDictionary(applVerID, ptr::shared_ptr<DataDictionary>( new DataDictionary(path) )); }
^
/usr/local/include/quickfix/DataDictionaryProvider.h:60:75: error: expected primary-expression before ‘>’ token
{ addApplicationDataDictionary(applVerID, ptr::shared_ptr<DataDictionary>( new DataDictionary(path) )); }
^
fix.cpp: In function ‘int main(int, char**)’:
fix.cpp:19:5: error: ‘MyApplication’ was not declared in this scope
MyApplication application;
^
fix.cpp:19:19: error: expected ‘;’ before ‘application’
MyApplication application;
^
fix.cpp:23:8: error: ‘application’ was not declared in this scope
(application, storeFactory, settings, logFactory /*optional*/);
^
root#luis:/home/luis/tradingbot/bot4# In file included from /usr/local/include/quickfix/Session.h:34:0,
In: command not found
root#luis:/home/luis/tradingbot/bot4# from fix.cpp:6:
from: can't read /var/mail/fix.cpp:6:
root#luis:/home/luis/tradingbot/bot4# /usr/local/include/quickfix/DataDictionaryProvider.h:54:72: error: ‘ptr::shared_ptr’ has not been declared
bash: /usr/local/include/quickfix/DataDictionaryProvider.h:54:72:: No such file or directory
root#luis:/home/luis/tradingbot/bot4# void addTransportDataDictionary(const BeginString& beginString, ptr::shared_ptr<DataDictionary>);
bash: syntax error near unexpected token `('
root#luis:/home/luis/tradingbot/bot4# ^
^: command not found
root#luis:/home/luis/tradingbot/bot4# /usr/local/include/quickfix/DataDictionaryProvider.h:54:82: error: expected ‘,’ or ‘...’ before ‘<’ token
bash: ’: No such file or directory
root#luis:/home/luis/tradingbot/bot4# void addTransportDataDictionary(const BeginString& beginString, ptr::shared_ptr<DataDictionary>);
bash: syntax error near unexpected token `('
root#luis:/home/luis/tradingbot/bot4# ^
^: command not found
root#luis:/home/luis/tradingbot/bot4# /usr/local/include/quickfix/DataDictionaryProvider.h:55:70: error: ‘ptr::shared_ptr’ has not been declared
bash: /usr/local/include/quickfix/DataDictionaryProvider.h:55:70:: No such file or directory
What am I doing wrong?
You need to provide an implementation of the MyApplication class and compile with the appropriate C++11 flags.
Your MyApplication object typically needs to derive from the FIX::Application class which is a pure virtual class and will require you to implement a series of methods such as onLogon(...) and toApp(...)
If you want to just get your code to compile as a first step you can try using the FIX::NullApplication class (defined in quickfix/Application.h) as your starting application object.
The quickfix library must be compiled with this pre-processor directive HAVE_STD_UNIQUE_PTR
Your application must provide an implementation for the MyApplication class and that implementation must inherit from FIX::Application

Mongo C++ Driver: mongo/client/dbclient.h: No such file or directory

I am trying to install the MongoDB C++ driver on my machine. I have followed the directions here, and everything seemed to install successfully. Still, I can't seem to include the headers. Here is a simple test program:
#include <cstdlib>
#include <iostream>
#include "mongo/client/dbclient.h"
void run() {
mongo::DBClientConnection c;
c.connect("localhost");
}
int main() {
try {
run();
std::cout << "connected ok" << std::endl;
} catch(const mongo::DBException &e) {
std::cout << "caught" << e.what() << std::endl;
}
return EXIT_SUCCESS;
}
Here are the errors I get:
g++ app/tutorial.cpp -pthread -lmongoclient -lboost_thread-mt -lboost_filesystem -lboost_program_options -lboost_system -o tutorial
app/tutorial.cpp:3:35: error: mongo/client/dbclient.h: No such file or directory
app/tutorial.cpp: In function ‘void run()’:
app/tutorial.cpp:6: error: ‘mongo’ has not been declared
app/tutorial.cpp:6: error: expected `;' before ‘c’
app/tutorial.cpp:7: error: ‘c’ was not declared in this scope
app/tutorial.cpp: In function ‘int main()’:
app/tutorial.cpp:14: error: ISO C++ forbids declaration of ‘mongo’ with no type
app/tutorial.cpp:14: error: expected `)' before ‘::’ token
app/tutorial.cpp:14: error: expected `{' before ‘::’ token
app/tutorial.cpp:14: error: ‘::DBException’ has not been declared
app/tutorial.cpp:14: error: ‘e’ was not declared in this scope
app/tutorial.cpp:14: error: expected `;' before ‘)’ token
Any help would be greatly appreciated.
The line app/tutorial.cpp:3:35: error: mongo/client/dbclient.h: No such file or directory indicates that g++ is having difficulty finding the installed headers. In the tutorial that you linked to, the box below the suggested compilation command states
You may need to use -I and -L to specify the locations of your mongo and boost headers and libraries.
I'll assume that the installation procedure placed your header files in /usr/local/include and libraries (e.g. libmongoclient.a) in /usr/local/lib. Then, try adapting the compilation command to read
g++ -I/usr/local/include -L/usr/local/lib -pthread -lmongoclient -lboost_thread-mt -lboost_filesystem -lboost_program_options -lboost_system app/tutorial.cpp -o tutorial

Unable to setup gtkmm

I am trying to setup gtkmm on my Windows 7 system. I have installed Glade 3.6.1 and gtkmm Development Environment 2.22.0-2.
When I tried to run the sample code below, I am unable to compile and run.
#include <gtkmm.h>
int main(int argc, char *argv[])
{
Gtk::Main kit(argc, argv);
Gtk::Window window;
Gtk::Main::run(window);
return 0;
}
The compile log:
Compiler: Default compiler Building Makefile:
"C:\Dev-Cpp\Makefile.win" Executing make... make.exe -f
"C:\Dev-Cpp\Makefile.win" main.o g++.exe -c main.cpp -o main.o
-I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include" -mms-bitfields -IC:/GTK/include/gtkmm-2.4 -IC:/GTK/lib/gtkmm-2.4/include -IC:/GTK/include/atkmm-1.6 -IC:/GTK/include/giomm-2.4 -IC:/GTK/lib/giomm-2.4/include -IC:/GTK/include/pangomm-1.4 -IC:/GTK/lib/pangomm-1.4/include -IC:/GTK/include/gtk-2.0 -IC:/GTK/include/gdkmm-2.4 -IC:/GTK/lib/gdkmm-2.4/include -IC:/GTK/include/atk-1.0 -IC:/GTK/include/glibmm-2.4 -IC:/GTK/lib/glibmm-2.4/include -IC:/GTK/include/glib-2.0 -IC:/GTK/lib/glib-2.0/include -IC:/GTK/include/sigc++-2.0 -IC:/GTK/lib/sigc++-2.0/include -IC:/GTK/include/cairomm-1.0 -IC:/GTK/lib/cairomm-1.0/include -IC:/GTK/include/pango-1.0 -IC:/GTK/include/cairo -IC:/GTK/include -IC:/GTK/include/freetype2 -IC:/GTK/include/libpng14 -IC:/GTK/lib/gtk-2.0/include -IC:/GTK/include/gdk-pixbuf-2.0 -IC:/GTK/include/libglademm-2.4
In file included from
C:/GTK/include/glibmm-2.4/glibmm/containerhandle_shared.h:24,
from C:/GTK/include/glibmm-2.4/glibmm/arrayhandle.h:23,
from C:/GTK/include/glibmm-2.4/glibmm.h:82,
from C:/GTK/include/gtkmm-2.4/gtkmm.h:87,
from main.cpp:1: C:/GTK/include/glibmm-2.4/glibmm/ustring.h:861: error: ISO C++ forbids
declaration of wostringstream' with no type
C:/GTK/include/glibmm-2.4/glibmm/ustring.h:861: error: expected;'
before "StreamType" C:/GTK/include/glibmm-2.4/glibmm/ustring.h:865:
error: `StreamType' does not name a type
C:/GTK/include/glibmm-2.4/glibmm/ustring.h:906: error: expected
constructor, destructor, or type conversion before '&' token
C:/GTK/include/glibmm-2.4/glibmm/ustring.h:906: error: expected ,' or
;' before '&' token C:/GTK/include/glibmm-2.4/glibmm/ustring.h:912:
error: expected constructor, destructor, or type conversion before '&'
token C:/GTK/include/glibmm-2.4/glibmm/ustring.h:912: error: expected
,' or;' before '&' token
C:/GTK/include/glibmm-2.4/glibmm/ustring.h: In member function void
Glib::ustring::FormatStream::stream(const T&)':
C:/GTK/include/glibmm-2.4/glibmm/ustring.h:1057: error:stream_'
undeclared (first use this function)
C:/GTK/include/glibmm-2.4/glibmm/ustring.h:1057: error: (Each
undeclared identifier is reported only once for each function it
appears in.)
C:/GTK/include/glibmm-2.4/glibmm/ustring.h: In member function void
Glib::ustring::FormatStream::stream(const char*)':
C:/GTK/include/glibmm-2.4/glibmm/ustring.h:1063: error:stream_'
undeclared (first use this function)
C:/GTK/include/glibmm-2.4/glibmm/ustring.h: In member function void
Glib::ustring::FormatStream::stream(char*)':
C:/GTK/include/glibmm-2.4/glibmm/ustring.h:1069: error:stream_'
undeclared (first use this function)
make.exe: * [main.o] Error 1
Execution terminated
Any help with the setup would be greatly appreciated.
Thanks!

G++ doesn't compile C++0x range-based for loop

I was experimenting with some of the new C++0x features with G++. Lambdas, auto, and the other new features worked like a charm, but the range-based for-loop failed to compile. This is the program I was testing:
#include <iostream>
#include <vector>
int main ()
{
std::vector<int> data = { 1, 2, 3, 4 };
for ( int datum : data )
{
std::cout << datum << std::endl;
}
}
I compiled it with:
g++ test.cpp -std=c++0x
I also tried gnu++0x, but the output was the same.
This was the output:
test.cpp: In function ‘int main()’:
test.cpp:8:21: error: expected initializer before ‘:’ token
test.cpp:12:1: error: expected primary-expression before ‘}’ token
test.cpp:12:1: error: expected ‘;’ before ‘}’ token
test.cpp:12:1: error: expected primary-expression before ‘}’ token
test.cpp:12:1: error: expected ‘)’ before ‘}’ token
test.cpp:12:1: error: expected primary-expression before ‘}’ token
test.cpp:12:1: error: expected ‘;’ before ‘}’ token
Thanks in advance for your help.
EDIT: I am using GCC version 4.5.2, which I now see is too old.
You need GCC 4.6 and above to get range-based for loops.
GCC's C++0x status
$ cat for.cpp
#include <iostream>
int main()
{
for (char c: "Hello, world!")
std::cout << c;
std::cout << std::endl;
return 0;
}
$ g++ -std=c++0x -o for for.cpp
$ ./for
Hello, world!
$ g++ --version
g++ (GCC) 4.6.1 20110325 (prerelease)

LEDA programming with c++:

I am a LEDA-6.3 user.
I have an error when compiling this simple code:
#include <LEDA/core/d_array.h>
#include <iostream>
using namespace std;
main()
{
d_array<string,string> dic;
dic["hello"] = "hallo";
dic["world"] = "Welt";
dic["book"] = "Buch";
dic["key"] = "Schluessel";
string s;
forall_defined(s,dic) cout << s << " " << dic[s] << endl;
}
G++ Compiler:
g++ -I$LEDAROOT/incl -L$LEDAROOT d_array.cpp /usr/lib/LEDA/libleda.a -lX11 -lm -o d_array
The ERROR:
d_array.cpp: In function ‘int main()’:
d_array.cpp:8: error: ‘d_array’ was not declared in this scope
d_array.cpp:8: error: expected primary-expression before ‘,’ token
d_array.cpp:8: error: expected primary-expression before ‘>’ token
d_array.cpp:8: error: ‘dic’ was not declared in this scope
Please if there is a guide for LEDA-6.3 give me the link
You probably mean leda::d_array or are forgetting using namespace leda;