boost compile error Mac OS X 10.7.4 - c++

I want to use boost on my Mac.
Mac OS X 10.7.4
Xcode 4.5
I installed boost by homebrew.
brew install boost
Boost version is 1.49.0.
And I set up my Xcode project.
Add Header search path.
/usr/local/Cellar/boost/1.49.0/include
Add libraries
libboost * .dylib
When I compile my project, I have many errors. Clang LLVM 1.0 Error.
( I want to upload an image, but I can't upload becase I don't have more than 10 reputation. )
use of undeclared identifier 'nullptr_t'; did you mean 'nullptr'?
use of undeclared identifier 'nullptr_t'; did you mean 'nullptr'?
too few template arguments for class template '__is_function'
use of undeclared identifier 'nullptr_t'; did you mean 'nullptr'?
field has incomplete type 'std::exception_ptr'
expected ';' at end of declaration list
no member named 'memcpy' in namespace 'std::__1'; did you mean 'memcpy'?
no member named 'memcpy' in namespace 'std::__1'; did you mean 'memcpy'?
expected ';' at end of declaration list
expected ';' at end of declaration list
C++ requires a type specifier for all declarations
'operator==' cannot be the name of a variable or data member
use of undeclared identifier 'nullptr_t'; did you mean 'nullptr'?
expected ';' at end of declaration
expected unqualified-id
expected ';' at end of declaration list
unknown type name 'nullptr_t'
unknown type name 'nullptr_t'
qualified reference to 'shared_ptr' is a constructor name rather than a type wherever a constructor can be declared
too many errors emitted, stopping now
I checked this question.
XCode with boost "Semantic Issue - undeclared identifier va_start"
But I couldn't find answers.
Please let me know if there is a solution.
The header file using boost is like this.
GLTexture.hpp
#pragma once
#ifndef __GL_TEXTURE_HPP__
#define __GL_TEXTURE_HPP__
// Standard libraries.
#include <iostream>
#include <fstream>
#include <string>
#ifdef _WIN32
#pragma warning (push)
#pragma warning (disable:4819)
#endif
// Smart pointers.
#include <boost/shared_ptr.hpp>
#include <boost/scoped_ptr.hpp>
#include <boost/shared_array.hpp>
// Foreach macros.
#include <boost/foreach.hpp>
// Regular expression.
#include <boost/regex.hpp>
// Image I/O.
#define png_infopp_NULL (png_infopp)NULL
#define int_p_NULL (int*)NULL
#include <boost/gil/gil_all.hpp>
#include <boost/gil/extension/io/jpeg_io.hpp>
#include <boost/gil/extension/io/png_io.hpp>
// File operations,
#include <boost/filesystem.hpp>
// Linear algebra,
#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/io.hpp>
// String functions.
#include <boost/algorithm/string.hpp>
// Serialization
#include <boost/serialization/serialization.hpp>
#include <boost/serialization/string.hpp>
#include <boost/serialization/vector.hpp>
#include <boost/archive/xml_iarchive.hpp>
#include <boost/archive/xml_oarchive.hpp>
#include <boost/serialization/version.hpp>
#ifdef _WIN32
#pragma warning (pop)
#endif
// OpenGL and OpenGL Utility Toolkit
#ifdef _WIN32
#include <GL/glew.h>
#include <GL/GLUT.h>
#elif defined __APPLE__
#include <OpenGL/OpenGL.h>
#include <GLUT/GLUT.h>
#endif
#include "TextureManager.hpp"
#include <time.h>
class TextureManager;
using namespace std;
/// function to convert RGB image to RGBA image.
/// Filling its alpha channel with 255.
/// This function is called from boost::gil::copy_and_convert_pixels()
namespace boost {
namespace gil {
template <> void color_convert<rgb8_pixel_t,rgba8_pixel_t>(const rgb8_pixel_t& src,rgba8_pixel_t& dst);
}
}
class GLTexture
{
public:
//Destructor
~GLTexture();
//Return instance of GLTexture
static boost::shared_ptr<GLTexture> getInstance(const std::string& filename, bool _isVolatile = true);
//Load image file and generate texture
bool LoadFromFile(boost::shared_ptr<GLTexture> texture);
//Bind texture when the texture exists. If the texture doesn't exist, this method generates a texture.
static void bindTexture(boost::shared_ptr<GLTexture> texture);
//Setter of texFileName
void setTextureFile(const std::string filename);
//Setter of volatile Flag
void setIsVolatile(bool _isVolatile);
//Getter of texture ID
inline const GLuint& getTextureID(void)const{
return this->texture;
};
//Overload of operator to sort list
friend bool operator <(const boost::shared_ptr<GLTexture>& texture1, const boost::shared_ptr<GLTexture>& texture2);
friend std::ostream& operator <<(ostream& os, const boost::shared_ptr<GLTexture>& texture);
public:
GLuint texture; //texture id
std::string texFileName; //image file path
int width; //width of image
int height; //height of image
clock_t start, end; //start is the timing of bindTexture, end is the timing of delete, these are used to sort list.
bool isVolatile; //the flag whether this texture is volatile or not. true is volatile, and false is not volatile. To keep texture, this is false.
bool isRead; //the flag whether this texture already exists in texturelist. true means "exists", false means "not exists".
boost::shared_ptr<boost::gil::rgba8_image_t> pixelData_ptr; //smart pointer to contain pixelData
boost::shared_ptr<boost::gil::rgba8_image_t::const_view_t> viewwithAlpha_ptr; //smart pointer to contain viewData
private:
//Forbid copy constructor
GLTexture();
GLTexture(const std::string& imageFilePath, bool _isVolatile = false);
GLTexture(const GLTexture& glTexture);
GLTexture& operator = (const GLTexture& glTexture);
//load image from SSD
bool LoadImage(const std::string& filename);
};
#endif
TextureManager.hpp
#pragma once
#ifndef __TEXTURE_MANAGER_HPP__
#define __TEXTURE_MANAGER_HPP__
// Standard libraries.
#include <iostream>
#include <fstream>
#include <string>
#ifdef _WIN32
#pragma warning (push)
#pragma warning (disable:4819)
#endif
// Smart pointers.
#include <boost/shared_ptr.hpp>
#include <boost/shared_array.hpp>
// Foreach macros.
#include <boost/foreach.hpp>
// Regular expression.
#include <boost/regex.hpp>
// Image I/O.
#define png_infopp_NULL (png_infopp)NULL
#define int_p_NULL (int*)NULL
#include <boost/gil/gil_all.hpp>
#include <boost/gil/extension/io/jpeg_io.hpp>
#include <boost/gil/extension/io/png_io.hpp>
// File operations,
#include <boost/filesystem.hpp>
// Linear algebra,
#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/io.hpp>
// String functions.
#include <boost/algorithm/string.hpp>
// Serialization
#include <boost/serialization/serialization.hpp>
#include <boost/serialization/string.hpp>
#include <boost/serialization/vector.hpp>
#include <boost/archive/xml_iarchive.hpp>
#include <boost/archive/xml_oarchive.hpp>
#include <boost/serialization/version.hpp>
#ifdef _WIN32
#pragma warning (pop)
#endif
// OpenGL and OpenGL Utility Toolkit
#ifdef _WIN32
#include <GL/glew.h>
#include <GL/GLUT.h>
#elif defined __APPLE__
#include <OpenGL/OpenGL.h>
#include <GLUT/GLUT.h>
#endif
#include "GLTexture.hpp"
class GLTexture;
class TextureManager
{
public:
TextureManager(void);
~TextureManager(void);
//Generate Texture
static void genTexture(boost::shared_ptr<GLTexture> texture);
static void setTexture(const boost::shared_ptr<GLTexture> texture);
static void deleteTexture();
static bool checkList(const std::string& filename);
private:
//Forbid copy constructor
TextureManager(const TextureManager& texManager);
TextureManager& operator = (const TextureManager& texManager);
};
#endif

Did you use recursive search path for the headers? If so change it to non-recursive. That might solve the problem.

I had similary problem!I soved the problem that:
Xcode->Buid Setting->C++ language Dialect(GNU++11)
->C++Standard Library(libc++(LLVM C++ with C++ 11)

I needed to add
#include <cstring>
http://en.cppreference.com/w/cpp/string/byte/memcpy

Related

identifier "test" is undefined; What does this mean in this context

I am writing a weather station for a raspberry. I'm always getting the error message identifier "test" is undefined.
I've already tried to use no external class with a little example and this works perfectly. Now I'm trying to create an object test, but this doesn't work. I am always getting the error message:
E0020 identifier "test" is undefined
main.cpp:
#include <wiringPi.h>
#include <stdio.h>
#include <iostream>
#include <cstring>
#include <errno.h>
#include <stdlib.h>
include "MeasureWeather.h"
int main(void)
{
MeasureWeather test;
while (1)
{
test._setSensorPin(DHT_PIN);
}
return 0;
}
MeasureWeather.h:
#ifndef MeasureWeather
#define MeasureWeather
#include <wiringPi.h>
#include <stdio.h>
#include <iostream>
#include <errno.h>
#include <stdlib.h>
#include <cstring>
class MeasureWeather
{
public:
//setter for sensor pin
void _setSensorPin(uint8_t pin);
private:
uint8_t sensorPin;
};
#endif // !MeasureWeather
MeasureWeather.cpp:
include "MeasureWeather.h"
void MeasureWeather::setSensorPin(uint8_t pin)
{
_sensorPin = pin;
}
I hope somebody can help me with my issue. Thank you!
You have this at the top of your header file, as part of the include guard:
#define MeasureWeather
MeasureWeather is the name of your class. By defining it as a macro, you hide the class name. Thus the line
MeasureWeather test;
expands to
test;
which would be a reference to something called test, not a declaration.
Use a different identifier for your #include guard.

Struct included in header throws incomplete type when instantiated locally but not when set as return value or vector

Ok, so this problem has been bugging me for a while. I'm creating a c++ program with the libpcap and libnet libraries. It will scan a given country for open ports by SYN'ing with libnet and checking for replies with libpcap. I have a main.cpp file that includes network.h which includes the source files necessary for generating the IPv4 ranges (regex.cpp) and for scanning them (libnet.cpp). Now, my network.h file contains the definition for struct range which is just two uint32_t's representing the starting address of the range and the end.
network.h:
#ifndef NETWORK_H
#define NETWORK_H
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <regex>
#include <fstream>
#include <libnet.h>
#include <pcap.h>
#include "src/regex.cpp"
#include "src/libnet.cpp"
#include "src/libpcap.cpp"
#define COLOR_GREEN "\x1b[32m"
#define COLOR_RED "\x1b[31m"
#define COLOR_RESET "\x1b[0m"
#define SNAP_LEN 1518
typedef struct range {
uint32_t begin;
uint32_t end;
} range;
#endif
And I use struct range as the return type for getRangeByCountry
#include "../network.h"
std::vector<struct range> getRangeByCountry(const char* country){
std::vector<struct range> ranges;
try {
std::ifstream f("csv/geoip.csv");
std::regex re("\"\\d+.\\d+.\\d+.\\d+\",\"\\d+.\\d+.\\d+.\\d+\",\"(\\d+)\",\"(\\d+)\",\"\\w$
while (1){
std::string line;
std::getline(f, line);
std::smatch m;
if(line == ""){break;}
std::regex_match(line, m, re);
if (m[3] == country){
struct range r;
r.begin = std::stoul(std::string(m[1]), NULL, 0);
r.end = std::stoul(std::string(m[2]), NULL, 0);
ranges.push_back(r);
}
}
} catch (...){return ranges;}
return std::move(ranges);
}
But when I compile I get this error:
src/regex.cpp: In function ‘std::vector<range> getRangeByCountry(const
char*)’:
src/regex.cpp:15:17: error: aggregate ‘range r’ has incomplete type and
cannot be defined
struct range r;
Why doesn't the compiler throw an error when I set declare a vector of struct range locally? Or when I set the same as the return type? When I define the struct in the same file as getRangebyCountry() it compiles without error. Is this a problem with my g++ parameters? Here they are just in case: g++ main.cpp -lpcap -lnet --std=c++11
Fixed the problem. #Walter and #IgorTandetnik were right. In network I included a definition for getRangeByCountry() and removed the .cpp includes like so:
#ifndef _NETWORK_H
#define _NETWORK_H
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <regex>
#include <fstream>
#include <libnet.h>
#include <pcap.h>
#define COLOR_GREEN "\x1b[32m"
#define COLOR_RED "\x1b[31m"
#define COLOR_RESET "\x1b[0m"
#define SNAP_LEN 1518
std::vector<struct range> getRangeByCountry(const char*);
typedef struct range {
uint32_t begin;
uint32_t end;
} range;
Then I compiled regex.cpp separately and included it in my compilation of main.cpp like so: g++ main.cpp src/regex.o
But I'm still really shakey on the concept. If I want to include other cpp source files, do I need to compile them separately then include their definition in a header file and their actual definition in a .o when I compile main.cpp?

C++ Definition of dllimport static data member not allowed

I am trying to compile the source/headers of some software into a static library, but am running into this dll issue. I haven't been able to run it down, and the standard #ifndef/#define _declspec(...) isn't working. I don't have a ton of C++ experience, so I'm probably just missing something important. Any help would be appreciated.
The errors occur on the last 4 lines of the section of source code, but I'm not sure how to fix it.
The header and source are a bit too long for here, but this is the jist:
Header(.h):
#ifdef CONVERSIONDLL_EXPORTS
#define CONVERSIONDLL_API __declspec(dllexport)
#else
#define CONVERSIONDLL_API __declspec(dllimport)
#endif
#ifndef ConversionUtility_h
#define ConversionUtility_h
#include <Config.h>
#include <iostream>
using namespace std;
#include <math.h>
#include <stdio.h>
#include <string>
#include <PropertyFileHandler.h>
#include <GWProperties.h>
#include <PureDataS.h>
#include <PureDataI.h>
class MSR_EXPORT Conversions {
Msr::GWFramework::Component::PropertyFileHandler propertyFileHandler_;
double sea_level_corr_;
public:
double static const PI;
double static const DEGREES_PER_RADIAN;
double static const FEET_PER_METER;
unsigned short static RTCODE_WGS_1984_IDENTITY;
...
Source(.cpp):
#include <CountdownTimer.h>
#include "ConversionUtility.h"
#include <Rotation.h>
#include <MsrConversionErrorException.h>
#include <sstream>
#include <stdlib.h>
#include <ctime>
#include <GWTime.h>
#include <GWManagerDefines.h>
double const Conversions::PI = 3.14159265359; // low precision: atan(1.0)*4;
double const Conversions::DEGREES_PER_RADIAN = 180/PI;
double const Conversions::FEET_PER_METER = 1/0.3048;
unsigned short Conversions::RTCODE_WGS_1984_IDENTITY = 341; // from TENA-TSPI tdl

newer gcc gives illegal syntax error in a header file

I've installed the mimetic library according to the INSTALL instructions.
the following main file compiles without a problem with a gcc-c++ 4.1.2,
but when I upgrade to gcc-c++ 4.4.7 I get an error.
mimetic.cpp:
#include <iostream>
#include <mimetic.h>
using namespace std;
using namespace mimetic;
int main()
{
MimeEntity me;
return 0;
}
error
In file included from /usr/local/include/mimetic/rfc822/header.h:18,
from /usr/local/include/mimetic/header.h:11,
from /usr/local/include/mimetic/mimetic.h:18,
from mimetic.cpp:2:
/usr/local/include/mimetic/rfc822/messageid.h:29: error: expected ‘)’ before ‘thread_id’
the header file:
rfc822/messageid.h
#ifndef _MIMETIC_MESSAGEID_H_
#define _MIMETIC_MESSAGEID_H_
#ifdef HAVE_STDINT_H
#include <stdint.h>
#endif
#include <string>
#include <mimetic/libconfig.h>
#ifdef HAVE_INTTYPES_H
#include <inttypes.h>
#endif
#include <mimetic/utils.h>
#include <mimetic/os/utils.h>
#include <mimetic/rfc822/fieldvalue.h>
namespace mimetic
{
/// Message-ID field value
/// On Win32 Winsock library must be initialized before using this class.
struct MessageId: public FieldValue
{
MessageId(uint32_t thread_id = 0 ); // <------ line 29
MessageId(const std::string&);
std::string str() const;
void set(const std::string&);
protected:
FieldValue* clone() const;
private:
static unsigned int ms_sequence_number;
std::string m_msgid;
};
}
#endif
is there some compatibility switch for the gcc ?
So, the problem turns out to be poor configuration of the system, which leaves HAVE_STDINT_H not configured, and thus the uint32_t doesn't get defined, and the error occurs.

Multiple definition of C++. How to split C++ program properly?

I wrote a program that works without problems, but the thing I am afraid of is that I get a lot of warnings, when I compile it with -Wall option ( it's program written in C and C++). Actually there is only one type of warning, but occurs many times : Multiple definition of .... ( contructors , destructors, and functions ). I thought I did it correcly, but obviously I am wrong. I have 9 files:
Server.h
Server.cpp - implements methods declared in Server.h
RankingCreator.h
RankingCreator.cpp - implements methods declared in RankingCreator.h
Parser.h
Parser.cpp - implements methods declared in Parser.h
PageHandler.h
PageHandler.cpp - implements methods declared in PageHandler.h
and
Main.cpp
- all header files are included in this file, because I use and combine
functionality of all classes here
Each .cpp file except Main.cpp contains only one corresponding .h file included, for instance Server.cpp contains #include "server.h" and no more .h/.cpp files listed above ( but it does contain headers like stdio.h and string.h ). I can post whole warning message here and code of classes, but the lenght of error is about 50 lines, and all classes would be about 1000 lines, so tell me if it is really needed to solve this. Any idea how to solve this? Do I have to make every function inline or something? Every header file has #if def block at the beginning.
EDIT:
Here is the warning log :
g++ LearnTidyCurl.cpp MyParser.cpp PageHandler.cpp RankingCreator.cpp Server.cpp -lcurl -ltidy -o -Wall Wynik
Here is code of one of my header files, see the way of ifdefs :
#ifndef RANKINGCREATOR_H_
#define RANKINGCREATOR_H_
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <vector>
#include <algorithm>
//using namespace std;
struct rankingElement {
std::string url;
int rank;
bool operator() (rankingElement i, rankingElement j) { return (i.rank > j.rank);}
} ;
bool operator==(const rankingElement& elem, const std::string& url);
class RankingCreator {
public:
rankingElement compareRankingElements;
const static int MAX_QUERY_RESULT_SIZE = 20;
RankingCreator();
virtual ~RankingCreator();
bool checkPageRank( rankingElement rElement, std::vector<rankingElement> &ranking );
void insertIntoRanking( rankingElement rElement, std::vector<rankingElement>& ranking);
};
#endif /* RANKINGCREATOR_H_ */
I threw warning message out, because it makes this topic unreadable.
Btw. I use include guards auto-generated by Eclipse - shouldn't they be just fine? ( When creating a new class they are automatically created )
EDIT:
You can download gedit file with error log here :
http://www4.zippyshare.com/v/62324366/file.html
I didn't want to post 105-lined error here and in addition it is in crap format, so would not good look here.
Server.h :
#ifndef SERVER_H_
#define SERVER_H_
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/wait.h>
#include <sys/select.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <iostream>
#include <sstream>
#include <vector>
...body...
#endif /* SERVER_H_ */
PageHandler.h
#ifndef PAGEHANDLER_H_
#define PAGEHANDLER_H_
#include <tidy.h>
#include <buffio.h>
#include <stdio.h>
#include <errno.h>
#include <iostream>
#include <string.h>
#include <curl/curl.h>
#include <vector>
#include <algorithm>
#include <stdexcept>
... body ...
#endif /* PAGEHANDLER_H_ */
MyParser.h
#ifndef MYPARSER_H_
#define MYPARSER_H_
#include <vector>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <sstream>
#include <algorithm>
#include <queue>
#include <stdlib.h>
...body...
#endif /* MYPARSER_H_ */
Main.cpp
#include <stdio.h>
#include <iostream>
#include <queue>
#include "MyParser.h"
#include "PageHandler.h"
#include "RankingCreator.h"
#include "Server.h"
#define NO_ERROR 0
std::string convertIntToString(int input) {
std::ostringstream ss;
ss << input;
std::string tmpStr = ss.str();
return tmpStr;
}
int main(int argc, char **argv) {
... body ...
return 0;
}
MyParser.cpp
#include "MyParser.h"
PageHandler.cpp
#include "PageHandler.h"
Server.cpp
#include "Server.h"
RankingCreator.cpp
#include "RankingCreator.h"
Change your inclusion guards:
#ifndef FILENAME_H
#define FILENAME_H
//Code
#endif
And I bet your problem goes away. Obviously make sure each FILENAME_H is unique :) And remember - each header needs this around all it's code, but it shouldn't be in your source files.
Write your header files the following way:
#ifndef SERVER_H
#define SERVER_H
//...
#endif
They are called #include guards to avoid double inclusion problems. Read about them here
If you are ever developing on MVSC++, you can use #pragma once as a first line of each header, but the first solution is portable on every platform.