C++, error: '__locale_t' has not been declared - c++

I'm new to C++, I got error: '__locale_t' has not been declared when I included some header files, like #include "ruby.h" , #include <string.h> and so on, but there's no problem for #include <stdio.h>, I'm using eclipse under Linux, the detailed error for #include "ruby.h" and #include <string.h> is:
/usr/include/string.h:548: error: '__locale_t' has not been declared
/usr/include/string.h:549: error: nonnull argument references non-pointer operand (argument 1, operand 3)
/usr/include/string.h:552: error: '__locale_t' has not been declared
/usr/include/string.h:553: error: nonnull argument references non-pointer operand (argument 1, operand 4)
The order of the include is:
#include "Abc.h"
#include <string.h>
#include "ruby.h"
#include <stdio.h>
Where Abc is the class name.
This is the Abc class, nothing added except the include:
#include "Abc.h"
#include <stdio.h>
#include <string.h>
#include "ruby.h"
#include "ose_gw.h"
namespace a {
Abc::Abc() {
// TODO Auto-generated constructor stub
}
Abc::~Abc() {
// TODO Auto-generated destructor stub
}
} /* namespace a */

Try compiling with:
g++ -D__USE_XOPEN2K8 ...
(see also https://sourceware.org/bugzilla/show_bug.cgi?id=10456 which mentions that xlocale.h is only included from string.h when __USE_XOPEN2K8 is defined)

This is apparently a known issue, which was logged as a bug but is actually some kind of subtle configuration error.
See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52922
I'm a Windows guy and this is out of my league, but the answer is in there somewhere (I think).

Related

Error: implicit declaration of function `int open(...)'

I am using open function in one of my C++ project on Solaris OS.
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
char in_pathname[PATH_MAX];
int in_fd = -1;
in_fd = ::open(in_pathname, (O_RDWR|O_CREAT|O_TRUNC), 0600);
Using the above line I am getting following compilation error.
implicit declaration of function `int open(...)'
Any idea why its happening.
Note: This source code is very old and I am using gcc version 2.95.3 to compile it.
Some (older) compilers will let you use a function you haven't declared and assume it returns int.
This will happen if you use a file but haven't included the header it is declared in. You seem to be using file's open method, and these docs suggest you therefore need
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

g++ how to solve warning "used but never defined"? (not static or inline)

I have come across a strange compile error that I cannot make sense of. Firstly the error refers to the function as if it was in an anonymous namespace, however it is in fact inside namespace database. Secondly the "used but never defined" statement suggests that the compile requires me to define the function from within the header. The function is in fact declared in a separate implementation file. However the function is neither static nor inline so I am at a loss as to why it requires a definition in the header. It is a requirement that this piece of code is strictly compliant, because of this I have compiled with both -Wall -Werror. I have also included a shortened version of my source code for clarification.
Note: This question is different from other similar questions asked here in that it does not involve static or inline functions.
Error:
In file included from src/main.cpp:6:0:
include/database.hpp:19:6: error: 'void {anonymous}::SetupSettings()' used but never defined [-Werror]
void SetupSettings();
^
cc1plus.exe: all warnings being treated as errors
main.cpp
#include <iostream>
#include "config.hpp"
#include "database.hpp"
int main() {
database::SetupSettings();
return 0;
}
database.hpp
#ifndef database
#define database
#include <iostream>
#include "config.hpp"
#include "sqlite/sqlite3.h"
namespace database {
extern sqlite3* settings_database;
void SetupSettings();
// ^^ Apparent warning here.
} // namespace database
#endif
database.cpp:
#include <iostream>
#include <vector>
#include "config.hpp"
#include "database.hpp"
#include "sqlite/sqlite3.h"
namespace database {
sqlite3* settings_database;
void SetupSettings() {/*More code here*/}
} // namespace database
The problem is caused by use of:
#ifndef database
#define database
After that,
namespace database { ...
is seen as
namespace { ...
i.e. an anonymous namespace.
You need to use a different include guard macro, such as:
#ifndef database_hpp
#define database_hpp

'sqrt' : ambiguous call to overloaded function ..\assimp\vector3.inl

Error
error C2668: 'sqrt' : ambiguous call to overloaded function c:\program files\assimp\include\assimp\vector3.inl
occures when I include 'scene.h' in main cpp file:
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
GLFWwindow* window;
#include <glm/glm.hpp>
#include <glm/gtx/transform.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <assimp/Importer.hpp>
#include <assimp/scene.h>
#include <assimp/postprocess.h>
#define MESH_FILE "cube.obj"
using namespace glm;
#include "common/shader.hpp"
#include "common/controls.hpp"
I can't get what does it conflict with?
You have a namespace using-directive in your .cpp file:
using namespace glm;
This means that everything that is in the glm namespace becomes part of the "global" namespace; so you are polluting the global namespace.
So, there might be some form of conflict between the standard C sqrt() function (which lives in the global namespace) and your glm::sqrt(), which is "promoted" to a global sqrt.
You may want to remove the aforementioned namespace using-directive (and just add the glm:: namespace prefix when you want to reference classes and functions in that namespace).

KEIL error: no instance of overloaded function "std::transform" matches the argument list

I have a problem that does no resurface (even no warnings) in XCode but does allow me to compile in Keil MDK.
void grammar::parse(std::string &_expr) {
std::transform(_expr.begin(), _expr.end(), _expr.begin(), std::tolower);
_expr.erase(std::remove_if(_expr.begin(), _expr.end(), std::isspace), _expr.end());
}
That is what I get
error: #304: no instance of overloaded function "std::transform" matches the argument list
error: #304: no instance of function template "std::remove_if" matches the argument list
Header included:
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <stdio.h>
#include <algorithm>
Could you please advise me on where to look? I am surprised that XCode version works as expected...
You include ctype.h, that header declares a function tolower in the global namespace (this is part of the C library, so there are no other namespaces there). Maybe you meant to include cctype. For a given C standard library header X.h, there is a c++ version cX that provides some of the same functionality inside the ::std namespace.

C++: variable 'ns3::Ipv4RoutingTableEntry route' has initializer but incomplete type

I am having trouble deciphering these error messages from g++
../upenn-cis553/ls-routing-protocol/ls-routing-protocol.cc:533:29: error: variable ‘ns3::Ipv4RoutingTableEntry route’ has initializer but incomplete type
../upenn-cis553/ls-routing-protocol/ls-routing-protocol.cc:533:64: error: invalid use of incomplete type ‘struct ns3::Ipv4RoutingTableEntry’
Here is my ls-routing-protocol.h file:
#include "ns3/ipv4.h"
#include "ns3/ipv4-routing-protocol.h"
#include "ns3/ipv4-static-routing.h"
#include "ns3/object.h"
#include "ns3/packet.h"
#include "ns3/node.h"
#include "ns3/socket.h"
#include "ns3/timer.h"
#include "ns3/ping-request.h"
#include "ns3/penn-routing-protocol.h"
#include "ns3/ls-message.h"
#include <vector>
#include <map>
...
private:
...
Ptr<Ipv4StaticRouting> m_staticRouting;
...
And here the relevant snippet from the ls-routing-protocol.cc file:
#include "ns3/ls-routing-protocol.h"
#include "ns3/socket-factory.h"
#include "ns3/udp-socket-factory.h"
#include "ns3/simulator.h"
#include "ns3/log.h"
#include "ns3/random-variable.h"
#include "ns3/inet-socket-address.h"
#include "ns3/ipv4-header.h"
#include "ns3/ipv4-route.h"
#include "ns3/uinteger.h"
#include "ns3/test-result.h"
#include <sys/time.h>
using namespace ns3;
void
LSRoutingProtocol::AuditRoutes ()
{
int i;
int n = m_staticRouting->GetNRoutes();
for (i=0; i < n; i++)
{
Ipv4RoutingTableEntry route = m_staticRouting->GetRoute(i); // ERROR
...
}
...
}
As some of you may tell, I am working with ns-3. I have looked up my error in many places, and most of the advice has been to properly declare a few structs. However, we are not directly using structs in this code (or at least not that I know of). I am starting to think that it's an issue with our use of smart pointers, but I'm not really sure.
Also, in case it is of any help: documentation for ipv4_static_routing.h
You need to #include <ipv4-routing-table-entry.h>. This is the first thing that you see when you look at the documentation of ns3::Ipv4RoutingTableEntry class.