I am trying to use std::vector in qt, but I seem to get some errors, When ever I include the vector header and compile the below code, I get a big list of errors but when I remove the vector header and compile the same code it works fine.
#include <iostream>
#include <vector>
using namespace std;
int main ()
{
std::cout<<"Vector"<<std::endl;
return 0;
}
Since there were lot of errors I decided to put them into a file and provide the link below.
http://goo.gl/XOj0nV
The beginning and the end of the build log:
12:03:19: Running steps for project vector...
12:03:19: Configuration unchanged, skipping qmake step.
12:03:19: Starting: "/usr/bin/make"
g++ -c -pipe -g -Wall -W -fPIE -I../../Qt/5.3/gcc/mkspecs/linux-g++ -I../vector -I. -o main.o ../vector/
main.cpp
In file included from ../vector/main.cpp:2:0:
./vector:1:1: error: stray '\177' in program
./vector:1:1: error: stray '\1' in program
./vector:1:1: error: stray '\1' in program
./vector:1:1: error: stray '\1' in program
./vector:1:8: warning: null character(s) ignored [enabled by default]
./vector:1:1: error: stray '\2' in program
./vector:1:18: warning: null character(s) ignored [enabled by default]
./vector:1:1: error: stray '\3' in program
./vector:1:20: warning: null character(s) ignored [enabled by default]
./vector:1:1: error: stray '\1' in program
./vector:1:22: warning: null character(s) ignored [enabled by default]
./vector:1:1: error: stray '\205' in program
./vector:1:1: error: stray '\4' in program
./vector:1:1: error: stray '\10' in program
./vector:1:30: warning: null character(s) ignored [enabled by default]
[...]
./vector:115:880: warning: null character(s) ignored [enabled by default]
./vector:115:886: warning: null character(s) ignored [enabled by default]
In file included from ../vector/main.cpp:2:0:
File: /home/sanjayan/Documents/qt_vector_errors Page 76 of 76
./vector:1:2: error: 'ELF' does not name a type
In file included from ../vector/main.cpp:2:0:
./vector:28:655: error: 'j' does not name a type
In file included from ../vector/main.cpp:2:0:
./vector:61:28: error: expected declaration before '}' token
make: *** [main.o] Error 1
12:03:22: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project vector (kit: Desktop Qt 5.3 GCC 32bit)
When executing step 'Make'
12:03:22: Elapsed time: 00:03.
I hope the provided information's is sufficient for my query.
I had the same problem like you just now.
I write a C++ program named vector.cc
#include <iostream>
#include <vector>
using namespace std;
int main()
{
cout << "hello" << endl;
return 0;
}
Compilation can pass for the first time (use g++ vector.cc -o vector, creates an executable file named vector), and then any program include the sentence #include vector will face the problems as you said.
The basic reason is the vector file, if the executable file (named "vector") is deleted, everything will be OK.
I hope my answer can help you.
If that problem arises not on every host then probably difference in the compiler. Difference is likely in the header files directory scan order. Such error should not arise if standard headers directory scanned before others.
As a workaround its enough to remove project target file manually befor building target. But this is not a programmers way (which are very lazy creatures).
Programmers way - is to learn QMake to delete target file just before project sources compilations (but under this way link phase will be done permanently). For me (QMake 2.01a under Linux) this is achived by addition of following lines into project file:
deltarget.commands = $$QMAKE_DEL_FILE $$TARGET
QMAKE_EXTRA_TARGETS += deltarget
PRE_TARGETDEPS += deltarget
This declares target deltarget which becomes built before current project. This sample uses undeclared in QMake's manual variable QMAKE_DEL_FILE which used to remove files (its content of course platfrom-dependent).
Related
I have compiled gcc 5.4.0 (make, make install into non root folder) and have exported it to anther machine of the same base distro. however when I try to compile a hello world on the 2nd machine I get an error for stdio.h and that cascades to cstdio etc.
for gcc I used configure --prefix=/home/mybin --bindir=/home/mybin/bin --libdir=/home/mybin/lib etc for all available folders as per --help.
On the gcc compile machine it seems the source folder /home/tmp/gcc-5.4.0/libstdc++-v3/include was installed into the --includedir=/home/mybin/include folder with all the sub directories.
Searching for stdio.h on the 5.4.0 compiling machine I get several folders that contain a version of stdio.h.
/home/tmp/gcc-5.4.0/libstdc++-v3/include/tr1/stdio.h
/home/tmp/gcc-5.4.0/libstdc++-v3/include/c_compatibility/stdio.h
/home/tmp/gcc-5.4.0/fixincludes/tests/base/rtldef/stdio.h
/home/tmp/gcc-5.4.0/fixincludes/tests/base/stdio.h
/home/tmp/gcc-5.4.0/libssp/ssp/stdio.h
/home/tmp/gcc-5.4.0/gcc/testsuite/gcc.dg/cpp/usr/include/stdio.h
and the search of the --prefix=/home/mybin/ returns
/home/mybin/lib/gcc/x86_64-unknown-linux-gnu/5.4.0/include/ssp/stdio.h
/home/mybin/include/c++/5.4.0/tr1/stdio.h
/home/mybin/include/c_compatibility/stdio.h
So I copied the ``--prefix=/home/mybin/` folder to the new machine and tried to use
gcc -Wall -I/home/mybin/include/c_compatibility /home/myuser/test.c -o /home/myuser/hello
this gives
In file included from /home/myuser/test.c:3:0:
/home/mybin/include/c_compatibility/stdio.h:29:18: fatal error: cstdio: No such file or directory
BUT I do have
/home/mybin/include/c++/5.4.0/tr1/cstdio
/home/mybin/include/c++/5.4.0/cstdio
/home/mybin/include/c_std/cstdio
/home/mybin/include/c/cstdio
so updated to
gcc -Wall -I/home/mybin/include/c_compatibility -I/home/mybin/include/c_std /home/myuser/test.c -o /home/myuser/hello
In file included from /home/mybin/include/bits/c++config.h:482:0,
from /home/mybin/include/c_std/cstdio:44,
from /home/mybin/include/c_compatibility/stdio.h:29,
from /home/myuser/test.c:3:
/home/mybin/include/bits/os_defines.h:39:22: fatal error: features.h: No such file or directory
compilation terminated.
BUT I do have /home/mybin/include/c++/5.4.0/parallel/features.h
gcc -Wall -I/home/mybin/include/c_compatibility -I/home/mybin/include/c_std /home/myuser/test.c -o /home/myuser/hello
In file included from /home/mybin/include/bits/c++config.h:482:0,
from /home/mybin/include/c_std/cstdio:44,
from /home/mybin/include/c_compatibility/stdio.h:29,
from /home/myuser/test.c:3:
/home/mybin/include/bits/os_defines.h:39:22: fatal error: features.h: No such file or directory
compilation terminated.
gcc -Wall -I/home/mybin/include/c_compatibility -I/home/mybin/include/c_std -I/home/mybin/include/c++/5.4.0/parallel /home/myuser/test.c -o /home/myuser/hello
In file included from /home/mybin/include/bits/c++config.h:482:0,
from /home/mybin/include/c_std/cstdio:44,
from /home/mybin/include/c_compatibility/stdio.h:29,
from /home/myuser/_test.c:3:
/home/mybin/include/bits/os_defines.h:44:19: error: missing binary operator before token "("
#if __GLIBC_PREREQ(2,15) && defined(_GNU_SOURCE)
^
In file included from /home/mybin/include/c_compatibility/stdio.h:29:0,
from /home/myuser/_test.c:3:
/home/mybin/include/c_std/cstdio:96:1: error: unknown type name 'namespace'
namespace std
^
/home/mybin/include/c_std/cstdio:97:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
{
^
/home/mybin/include/c_std/cstdio:155:1: error: unknown type name 'namespace'
namespace __gnu_cxx
^
/home/mybin/include/c_std/cstdio:156:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
{
^
/home/mybin/include/c_std/cstdio:181:1: error: unknown type name 'namespace'
namespace std
^
/home/mybin/include/c_std/cstdio:182:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
{
^
/home/myuser/_test.c:7:1: warning: return type defaults to 'int' [-Wimplicit-int]
main()
^
/home/myuser/test.c: In function 'main':
/home/myuser/test.c:9:5: warning: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
printf("Heh now");
^
/home/myuser/_test.c:9:5: warning: incompatible implicit declaration of built-in function 'printf'
/home/myuser/_test.c:9:5: note: include '<stdio.h>' or provide a declaration of 'printf'
I have tried exporting LD config flags as well
How do I know what folder to export and to other machines made from the same base image so I can compile with this version. Why are the includes not being found or getting confused?
I am using centos7
I have several programs that I have been writing under a master branch, which I compile using GNUmakefile. Today, right after I created a new branch, v4.3, and switched onto the new branch, and then compile, I get the following error message:
lucerne:lucerne$ make primes
g++-mp-4.8 -std=gnu++0x -g -O2 -W -Wall -Wextra -MD -MF .deps/primes.d -MP -I. -c -o primes.o primes.cpp
In file included from primes.cpp:2:0:
./vector:1:1: error: stray '\317' in program
????_TEXT
^
./vector:1:1: error: stray '\372' in program
./vector:1:1: error: stray '\355' in program
./vector:1:1: error: stray '\376' in program
./vector:1:1: error: stray '\7' in program
./vector:1:6: warning: null character(s) ignored [enabled by default]
./vector:1:1: error: stray '\1' in program
./vector:1:1: error: stray '\3' in program
./vector:1:10: warning: null character(s) ignored [enabled by default]
./vector:1:1: error: stray '\200' in program
I get the same error message when I switch to master branch. However, if I rename the file to something else, like "new_primes.cpp", then make file does not cause any problem. Neither GNUmakefile or prime.cpp has been modified. I also have not installed any additional packages. It is also not the editor - I am using emacs and TextWrangler. What is causing this problem?
The error generated by GCC occurs when the source file, or in this case, included file is a binary file. This is easily reproduced by creating a source file with a single include to a binary file, /bin/ls for example. Create stray.c with:
#include "/bin/ls"
A quick complie:
gcc -c stray.c
Yields the following output:
In file included from stray.c:1:0:
/bin/ls:1:1: error: stray '\177' in program
/bin/ls:1:1: error: stray '\2' in program
/bin/ls:1:1: error: stray '\1' in program
/bin/ls:1:1: error: stray '\1' in program
/bin/ls:1:8: warning: null character(s) ignored [enabled by default]
/bin/ls:1:1: error: stray '\2' in program
/bin/ls:1:18: warning: null character(s) ignored [enabled by default]
It appears that 'vector' is a binary file.
There are two possible causes that come to mind:
The C++ 'vector' header file is corrupt.
There is another 'vector' in your search path.
I'm guessing its the second. Check and make sure you don't have a binary called vector within the compiler include path.
I've been trying to compile some codes in windows but I got this error: 'flann_index_t' does not name a type'
where is this error come from?
Can any one help me to fix this?
g++ -I. -Iflann/src/cpp -c -o src/main.o src/main.cpp
In file included from ./boost/asio/async_result.hpp:18,
from ./boost/asio.hpp:20,
from src/common.hpp:30,
from src/main.cpp:9:
./boost/asio/detail/config.hpp:367:5: warning: #warning Please define _WIN32_WIN
NT or _WIN32_WINDOWS appropriately.
./boost/asio/detail/config.hpp:368:5: warning: #warning For example, add -D_WIN3
2_WINNT=0x0501 to the compiler command line.
./boost/asio/detail/config.hpp:369:5: warning: #warning Assuming _WIN32_WINNT=0x
0501 (i.e. Windows XP target).
In file included from src/common.hpp:50,
from src/main.cpp:9:
src/CBIR.hpp:32: error: 'flann_index_t' does not name a type
./flann/util/matrix.h: In function 'int cbir::main(int, char**)':
./flann/util/matrix.h:75: error: 'flann::uchar* flann::Matrix_::data' is protected
src/main.cpp:39: error: within this context Makefile:43: recipe for target `src/main.o' failed
make: *** [src/main.o] Error 1
Assuming you are using flann, then you need:
#include <flann.h>
in CBIR.hpp.
I'm running into a strange issue when I try to compile the following simple C++11 code on my machine:
#include <boost/thread/thread.hpp>
It compiles fine with g++ foo.cpp -o foo but chokes on g++ -c -std=c++11 foo.cpp -o foo with the following error:
In file included from /usr/local/lib/gcc/x86_64-apple-darwin11.4.0/4.7.1/../../../../include/c++/4.7.1/functional:56:0,
from /usr/local/lib/gcc/x86_64-apple-darwin11.4.0/4.7.1/../../../../include/c++/4.7.1/memory:81,
from /usr/local/include/boost/config/no_tr1/memory.hpp:21,
from /usr/local/include/boost/smart_ptr/shared_ptr.hpp:27,
from /usr/local/include/boost/shared_ptr.hpp:17,
from /usr/local/include/boost/thread/pthread/thread_data.hpp:10,
from /usr/local/include/boost/thread/thread.hpp:17,
from foo.cpp:1:
./tuple:1:1: error: stray ‘\317’ in program
./tuple:1:1: error: stray ‘\372’ in program
./tuple:1:1: error: stray ‘\355’ in program
./tuple:1:1: error: stray ‘\376’ in program
... Additional lines omitted
I'm at a loss. Especially since I've been able to compile other programs against C++11 without any issue. Any ideas?
I'm running OS X v10.7.4 (Lion) and GCC 4.7.1.
That's because you have a file in your current directory named tuple that is included instead of the standard tuple header. Probably because of some -I. in the compilation line.
The strays characters in the error messages are simply the first bytes of the file not in the allowed character set, in octal.
I get the following error when compiling this third-party library (called azove 2.0) which relies on the GNU Multi-precision library:
> make
g++ -Wall -O3 -DFIX_NUMBER_OF_SIGMDDNODE_SONS -DUSE_TIMER -I. -c conBDD.cpp -o conBDD.o
In file included from conBDDnode.hpp:27,
from conBDD.hpp:25,
from conBDD.cpp:22:
/usr/include/gmpxx.h: In destructor ‘__gmp_alloc_cstring::~__gmp_alloc_cstring()’:
/usr/include/gmpxx.h:2096: error: ‘strlen’ was not declared in this scope
conBDD.cpp: In member function ‘void conBDD::build()’:
conBDD.cpp:61: error: ‘numeric_limits’ was not declared in this scope
conBDD.cpp:61: error: expected primary-expression before ‘int’
conBDD.cpp:61: error: expected `;' before ‘int’
conBDD.cpp:68: error: expected primary-expression before ‘int’
conBDD.cpp:68: error: expected `;' before ‘int’
make: *** [conBDD.o] Error 1
I have tried adding either and both of the following lines
#include <cstdlib>
using std::strlen;
to conBDD.cpp, but the error persists.
I can't tell if this is an error comes from GNU's Multi-precision library or from Azove. Any pointers would be greatly appreciated.
I would start by apportioning blame. Create an empty cpp file, say test.cpp, in your project and include only the offending gmpxx.h file. If you can compile test cpp, GMP is off the hook. Then try including only the offending azove header. If you can compile the azove header in an otherwise empty file, azove is off the hook and something you are including/defining is interfering with them. Once you have narrowed down the source of the problem you should find it easier to fix.