g++

Benchmarking math.h square root and Quake square root.

Okay so I was board and wondered how fast math.h square root was in comparison to the one with the magic number in it (made famous by Quake but made by SGI). But this has ended up in a world of hurt for me. I first tried this on the Mac where the math.h would win hands down every time then on Windows where the magic number always won, ...

How do I get make to figure out the correct dependencies to link in the correct downstream object files?

I'm going to use a small example for reference. Consider a project with: inner_definitions.o : inner_definitions.cpp inner_definitions.h gcc $^ -o $@ inner_class_1.o : inner_class_1.cpp inner_class_1.h inner_definitions.h gcc $^ -o $@ inner_class_2.o : inner_class_2.cpp inner_class_2.h inner_definitions.h gcc $^ -o $@ ...

C++ map declaration under g++

I have such declaraition using namespace std; map < string, string> attr; if i write it in class or in global namespace it is compiled ok, but if I write it inside function it doesn't. Why? How can I solve it ? ...

How do I tell `gar` or `ar` to output `elf32-i386` output?

When I look at the help output from gar -h, it tells me: [...] gar: supported targets: elf64-x86-64 elf32-i386 a.out-i386-linux [...] How can I instruct gar to create an elf32-i386 output? ...

SetWindowsHookEx, CBTProc and g++3.4.5 (mingw)

Hi, I'm currently working on an application that needs to add a menu to each application's system menu. I can accomplish that for the existing windows with the EnumWindows function. For the new windows (applications starting up after mine) I'm trying to do this with windows hooks. More specifically with CBTProc. This is where I'm stuck....

Linking libpng with g++.

I'm trying to get libpng working on linux. I couldn't get it to work through netbeans, so I ran g++ directly as g++ -lpng -lz main.cpp -o test and it compiles. When I try to run it it it outputs ./test: error while loading shared libraries: libpng14.so.14: cannot open shared object file: No such file or directory. I assume this means I a...

Compiling & linking multiple files in C++

One of my "non-programmer" friends recently decided to make a C++ program to solve a complicated mechanical problem. He wrote each function in a separate .cpp file, then included them all in the main source file, something like this: main.cpp: #include "function1.cpp" #include "function2.cpp" ... int main() { ... } He then compile...

Has anyone an example for wrapping a function in C++?

I have searched online a lot but I couldn't find an example that works with g++, all examples work with gcc. The error I keep getting is wrap_malloc.o: In function `__wrap_malloc(unsigned int)': wrap_malloc.cc:(.text+0x20): undefined reference to `__real_malloc(unsigned int)' wrap_malloc.o: In function `main': wrap_malloc.cc:(.text+0x37...

compile rapidxml under linux with g++

The following simple program can't be compiled with gcc 4.4.3 include "rapidxml.hpp" include "rapidxml_utils.hpp" include "rapidxml_print.hpp" include "rapidxml_iterators.hpp" int main() { return 0; } ------------------------------------------------------------ Compile produces following errors: rapidxml_iterators.hpp:21: e...

C++ std::ifstream in constructor problem

Hello. I've got a problem with this code: #include <fstream> struct A { A(std::ifstream input) { //some actions } }; int main() { std::ifstream input("somefile.xxx"); while (input.good()) { A(input); } return 0; } G++ outputs me this: $ g++ file.cpp file.cpp: In function `int mai...

G++ preprocessor does not pick up -D defines

Where am I going wrong; I want to define a preprocessor value on the command-line for g++ but it fails. Below is sample code that replicate my problem: [edit] I'm using:g++ (Debian 4.3.2-1.1) 4.3.2GNU Make 3.81 test.h #ifndef _test_h_ #define _test_h_ #include "iostream" #if defined(MY_DEFINED_VALUE) #if (MY_DEFINED_VALUE != 5) #und...

Trouble with g++ & libpqxx lib

Hi2all, I've very simple example, and can't correctly build it, I was using next arguments: g++ -lpq -libpqxx -Wall -o "pg" "pg.cpp" (in dir: /home/user) /usr/lib/gcc/i586-suse-linux/4.5/../../../../i586-suse-linux/bin/ld: cannot find -lpq collect2: ld returned 1 exit status or returned 1 exit status g++ -libpqxx -Wall -o ...

wfstream not writing

I have the following piece of code in C++: #include <iostream> #include <fstream> #include <string> using namespace std; int main(){ wstring ws1 = L"Infinity: \u2210"; wstring ws2 = L"Euro: €"; wchar_t w[] = L"Sterling Pound: £"; wfstream out("/tmp/unicode.txt"); out.write(ws1.c_str(), ws1.size()); out << ws1...

Is there any XML Parser that comes by default with g++

PHP, C# is bundled with such parsers and are available with the default libraries. Does g++ have any such libraries? ...

facet's get_time keeps failing

I have spend like one out in this example, and everytime I get the error Unable to read cin with an ios_base::iostate equal to failbit from this code: #include "dates.h" #include <iostream> #include <ctime> #include <locale> #include <sstream> #include <iterator> using namespace std; void trasnlateDate(istream&in, ostream&out){ c...

In Linux using C++ and GCC, is it possible to convert the virtual address to a physical address?

Under Linux, C++, and GCC, can I get a physical address for a given virtual address? I know I won't be able to manipulate the physical address as a physical address. ...

How to forward declare a template class?

Hi, I tried this : #ifndef __TEST__ #define __TEST__ namespace std { template<typename T> class list; } template<typename T> void Pop(std::list<T> * l) { while(!l->empty()) l->pop(); } #endif and used that function in my main. I get errors. Of course, I know that there are more template params for std::list...

Static lib loading related problem - please help

Hi all, Suppose I want to version the libs in binaries made. For static libs, I thought this approach would work but it does not: LibInfo.h - Base class for all libinfo classes. Registers an object in gvLibInfo vector when a child is constructed. #ifndef IFACE_H #define IFACE_H #include <vector> class LibInfo; extern std::ve...

How to view symbols in object files?

Hi, How can I view symbols in a .o file? nm does not work for me. I use g++/linux. ...

Variable dissapears in binary which is available in static lib

Hi, I have the problem mentioned. I create an object inside a static lib, it is there when I run nm on the static lib, but when i link the lib to a binary and run nm it has disappeared. I know this problem has been asked before, but I could not find any answers. It is important for me to be able to retain that variable in the binary ...