Are tr1 headers available for g++ v3.4.6? If so, how can I locate them at compile time.
The following is failing to compile:
#include <tr1/memory>
With the following error:
myModule.h:20:24: tr1/memory: No such file or directory
Do I need to move to a later compiler or do I have the headers somewhere?
As an alternative, Boost provides a TR1 implementation too.
Related
I have two versions of boost installed, one in ~/local_opt/ and one in /usr/include. I would like to use the former one, after it provides some newer functions. Thus I am compiling my program with
g++ -I/home/<>/local_opt/boost/include main.cpp
Nevertheless it fails with
/home/<>/local_opt/boost/include/boost/math/interpolators/cubic_b_spline.hpp:25:69: fatal error: boost/math/interpolators/detail/cubic_b_spline_detail.hpp: No such file or directory
Thus I assume that it still tries to use the boost functions in /usr/include, and not my own version of boost. Why? How can I override the search path properly?
Recently, I met a very annoying problem. I need to compile some old C++ codes which was compiled with a very old g++ version 4.1.2.
I couldn't find g++ version that old now, so I used g++ 4.4.7 to compile it, but there were many errors like error: ‘snprintf’ was not declared in this scope.
After some work, I found g++ 4.1.2 do NOT distinguish <string> from <string.h>, also <stdio> from <stdio.h>, etc.. But g++ 4.4.7 DOES. So these errors happened.
For some reasons, I couldn't modify the old source code. Is there a way that can make the newer g++ ignore the difference between <string> and <string.h>?
Create a directory in your project (let's call it foo);
Create foo/string and foo/string.h as symlinks to whichever header works;
Add -Ifoo to GCC's compilation flags.
Both symlinks will now be used when you include <string> or <string.h>, and will redirect to the actual system header.
I have seen string and string.h usually implemented as just files (the first string filename is without an extension).
To not include the standard include paths you need to specify: -nostdinc
I have an iOS project set up like this:
I use XCode 6.1.1
clang -v says LLVM version 6.0
I use the flag -miphoneos-version-min=6.1 (I don't set -std and -stdlib)
Everything's fine.
When I update to -miphoneos-version-min=7.1 I have following errors in code includes the header new.h
Because it is a big project, I have created a new .h file that include new.
The problem is that the new header includes exception that includes type_traits header. 'type_traits' is a c++11 header. Because I am not using C++11, this raises errors.
I don't want to activate c++11 now.
I tried -miphoneos-version-min=7.1 -std=c++98 -stdlib=libc++ but whatever I try, I still have the new header leading to type_traits header leading to errors.
Any idea how can I build with -miphoneos-version-min=7.1? And why when I was with -miphoneos-version-min=6.1 the include new.h was fine (and not including type_traits header)
I'm trying to understand how to compile C++ programs from the command line using g++ and (eventually) Clang on Ubuntu.
I found a webpage which explains MakeFiles and I am following their directions. http://mrbook.org/tutorials/make/
I downloaded the four example files into their own directory.
main.cpp
hello.cpp
factorial.cpp
functions.h
I then went ahead and ran their example of how to manually compile without a MakeFile.
g++ main.cpp hello.cpp factorial.cpp -o hello
When I ran the command from above, I received the following error from g++:
main.cpp:1:22: fatal error: iostream.h: No such file or directory
compilation terminated.
hello.cpp:1:22: fatal error: iostream.h: No such file or directory
compilation terminated.
My only experience with writing c++ is using an IDE such as VS C++ Express or CodeBlocks. Isn't the compiler supposed to know what iostream.h is and where to find it?
How do I get rid of this error so the program willl compile?
Thanks for any help.
Before the C++ language was standardized by the ISO, the header file was named <iostream.h>, but when the C++98 standard was released, it was renamed to just <iostream> (without the .h). Change the code to use #include <iostream> instead and it should compile.
You'll also need to add a using namespace std; statement to each source file (or prefix each reference to an iostream function/object with a std:: specifier), since namespaces did not exist in the pre-standardized C++. C++98 put the standard library functions and objects inside the std namespace.
<iostream.h> has never been a standard C++ header, because it did not make it into the C++ standard.
Instead we got <iostream>, in 1998.
Steer well clear of teaching material using non-standard stuff such as <iostream.h> or void main.
However, as a practical solution for your current pre-standard code, you may try to replace
#include <iostream.h>
with
#include <iostream>
using namespace std;
It’s not guaranteed to work, but chances are that it will work.
Another related issue that wasn't mentioned here, so I will include it for anyone's future reference, is from the command line the compiler needs the environment path variable updated to find the location of the c++ header files. In windows you can just update the path environment using the 'advanced system properties' GUI and add the location of the c++ include files. This will update the PATH environment variable in Windows cmd & Cygwin automatically upon restarting the shell.
To update your PATH from Linux or the Cygwin shell type...
PATH=$PATH:/your_path_here
Example:PATH=$PATH:/cygdrive/c/cygwin/lib/gcc/i686-pc-mingw32/4.7.3/include/c++
Also a good idea to add just the include directory as well:
PATH=$PATH:/cygdrive/c/cygwin/lib/gcc/i686-pc-mingw32/4.7.3/include/
...or check the proper directories for the location of your installation's include files, I recommend installing mingw for use with Cygwin, which is envoked with g++.
To install additional needed packages in Cygwin re-run the Cygwin install utility & check install from Internet to add packages from web repositories and add mingw-gcc-g++ & mingw-binutils.
To compile: g++ hello.cpp -o hello
If using the gcc utility instead compile with the command:
gcc hello.cpp -o hello -lstdc++
... to get your executable.
As long as you have either gcc or mingw installed and the path to the c++ include files is in your path environment variable, the commands will work.
I have a project that uses log4cxx, boost, etc. libraries whose headers generate lots of (repetitive) warnings. Is there a way to suppress warnings from library includes (i.e. #include <some-header.h>) or includes from certain paths? I'd like to use -Wall and/or -Wextra as usual on project code without relevant info being obscured. I currently use grep on make output but I'd like something better.
You may try to include library headers using -isystem instead of -I. This will make them "system headers" and GCC won't report warnings for them.
For those using CMake, you can modify your include_directories directives to include the symbol SYSTEM which suppresses warnings against such headers.
include_directories(SYSTEM "${LIB_DIR}/Include")
^^^^^^
You can use pragmas. For example:
// save diagnostic state
#pragma GCC diagnostic push
// turn off the specific warning. Can also use "-Wall"
#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_generators.hpp>
#include <boost/uuid/uuid_io.hpp>
#include <boost/lexical_cast.hpp>
// turn the warnings back on
#pragma GCC diagnostic pop
I found the trick. For library includes, instead of -Idir use -isystem dir in the makefile. GCC then treats boost etc. as system includes and ignores any warnings from them.
#pragma are instructions to the compiler. you can set something before the #include and disable it after.
You can also do it at the command line.
Another GCC page specifically on disabling warnings.
I would go for the option of using #pragma's within the source code, and then providing a
sound reason (as a comment) of why you are disabling the warnings. This would mean reasoning about the headers files.
GCC approaches this by classifying the warning types. You can classify them to be warnings or to be ignored. The previously linked articles will show you which warnings are may be disabled.
Note: you can also massage the source code to prevent certain warnings by using attributes; however, this bind you quite closely to GCC.
Note2: GCC also uses the pop/push interface as used in microsoft's compiler -- Microsoft disables warnings through this interface. I suggest you investigate this further , as I do not know if it is even possible.
Putting the following
#pragma GCC system_header
will turn off GCC warnings for all following code in this file.
You can try using precompiled headers. Warnings won't go away but at least the won't show up in your main compilation.
If you need to explicitly override a system header then you're restricted to pragmas. You can verify which includes you're using via make depend output.
Also see diagnostic push-pop for gcc >= 4.6
Another way to do it is, in the makefile, to tell the compiler to ignore warnings for the specific folder:
$(BUILD_DIR)/libs/%.c.o: CFLAGS += -w
There must be reasons for those warnings. These will either be caused by errors in your code that uses the library, or by errors in the library code itself. In the first case, fix your code. In the second case, either stop using the library or if it is FOSS code, fix it.