sanjayan ravi
sanjayan ravi

Reputation: 143

qt #include <vector> error

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.

Upvotes: 3

Views: 2265

Answers (2)

fighter_yy
fighter_yy

Reputation: 75

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).

Upvotes: 0

Ryan_yang
Ryan_yang

Reputation: 11

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.

Upvotes: 1

Related Questions