"Illegal block entry" with YAML monsters example in yaml-cpp - c++

I am running the example found here to try out using YAML in C++. I copied the code verbatim into test.cpp in a new project folder. I compiled YAML into a static library and am linking it to my project. I'm running Ubuntu 11.10. I use the following command to compile:
g++ -Wall -I. -g test.cpp -lyaml-cpp -L.
I get the following error statement:
terminate called after throwing an instance of 'YAML::ParserException'
what(): yaml-cpp: error at line 4, column 2: illegal block entry
Aborted
What is the meaning of this exception? And what could be wrong? I couldn't find a clear documentation for what each of the exceptions could mean, so even a link to this information would be helpful. I am probably out of my depth, as I am new to YAML, using libraries, and linux for that matter. Thanks in advance for your help.
Edit: The error occurs before "parser.GetNextDocument(doc)". Also, I ran a simpler example from the website that stores a single scalar, and that worked fine. Is the exception about my input file, or my code?

The error indicates that there's a problem with the input file (monsters.yaml). Make sure you copied it exactly. It claims there's an error at line 4, column 2, so you can look at that spot first (but yaml-cpp isn't great with location of errors, so that may not be the right spot to look at).
Things to make sure about:
spaces, not tabs
the proper number of spaces for indentation

Related

Eclipse compilation and make file

I'm new to Eclipse. Despite its best efforts I got it to compile and run a
Hello World program. I am now trying to bring in a simple program I wrote that worked on MS Visual Studio 2010.
A user in reddit learnprogramming said I was missing a quotation mark in my make file, but I am using automatic make files. I don't know how to write my own and would rather work on the other 50 things wrong with the program. The Eclipse make file help page is technobabble to me.
I think Eclipse is not trying to build the files in the correct order, but I cannot find how to change the build order or how to point it towards the correct file to begin with. When I created the files in Eclipse, I hit "New Class" and then just copied and pasted in the old files. There are no red or yellow flags in the left margin indicating there are any problems. The file with the main method is Tier.cpp, but I believe it's trying to start with Player.cpp.
The compiler error is the very user friendly and easy to read:
01:31:42 **** Incremental Build of configuration Debug for project VanillaWoW ****
make all
Building file: ../VanillaWoWSource/Player.cpp
Invoking: Cross G++ Compiler
g++ -I"C:\cpp\boost_1_66_0\boost" -I"C:\cyg\bin"
-I"C:\cyg\lib\gcc\x86_64-pc-cygwin\6.4.0\include"
-I"C:\cyg\lib\gcc\x86_64-pc-cygwin\6.4.0\include\c++"
-I"C:\cyg\lib\gcc\x86_64-pc-cygwin\6.4.0\include\c++\backward"
-I"C:\cyg\lib\gcc\x86_64-pc-cygwin\6.4.0\include\c++\x86_64-pc-cygwin"
-I"C:\cyg\usr\include" -I"C:\cyg\usr\include\w32api"
-I"c:\cpp\boost_1_66_0\" -I"C:\cyg\lib\gcc\x86_64-w64-mingw32\6.4.0\include\c++"
-O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"VanillaWoWSource/Player.d"
-MT"VanillaWoWSource/Player.o"
-o "VanillaWoWSource/Player.o" "../VanillaWoWSource/Player.cpp"
/bin/sh: -c: line 0: unexpected EOF while looking for matching `"'
/bin/sh: -c: line 1: syntax error: unexpected end of file
make: *** [VanillaWoWSource/subdir.mk:26: VanillaWoWSource/Player.o] Error 1
I don't understand why it's throwing an error on line 26 of an object file that I didn't think it had fully even created yet. I don't know what /bin/sh: -c refers to, and I don't know which file it's hitting the end of file on.
Full code is at :
https://docs.google.com/document/d/185sOHxk3wKAnl6N0oCSvlJZB7WUTY8gEtZCsLIr1q0o/edit?usp=sharing
Now I formatted up your error messages, I can see the problem:
-I"c:\cpp\boost_1_66_0\" -I"C:\cyg\lib\gcc\x86_64-w64-mingw32\6.4.0\include\c++"
Note the boost_1_66_0\" - the trailing backslash escapes the quote character, so the text colouring goes wonky. Look where you set up paths and either remove the trailing backslash, or better, use forward slashes throughout. Windows will accept them, and you won't get bitten by mysterious escape problems.
I'm not sure why getting C++ set up is so difficult for you. It might have something to do with you using Eclipse -- it's really more of a Java IDE, and I'd suggest using something that's built for C++. When I was starting C++, I wrote with Code::Blocks and it worked great for me. I'd suggest switching to that.
C++ is a lower level language than Java. It's arguably more difficult to program in because of that. Although I do think the brunt of your issue is more because of the environment you're coding in.

Suppress g++ warning message "resolving __ZSt4cout" on Windows 7 [duplicate]

I am trying to compile the following program:
#include <iostream>
int main(){
std::cout << "Hello, world!";
return 0;
}
When I compile it, I get this message:
C:\programs>g++ test.cpp
Info: resolving std::cout by linking to __imp___ZSt4cout (auto-import)
c:/mingw/bin/../lib/gcc/mingw32/4.5.0/../../../../mingw32/bin/ld.exe: warning: a
uto-importing has been activated without --enable-auto-import specified on the c
ommand line.
This should work unless it involves constant data structures referencing symbols
from auto-imported DLLs.
The build succeeds and the executable runs as expected, but this warning still irritates me. I expect a successful build to be completely silent. This message gives the false impression that there's something wrong with my code.
I can silence this error with g++ -Xlinker --enable-auto-import test.cpp, but this is undesirable, as it triples the number of characters I need to type to compile a program.
Questions:
Why does this warning appear for the simplest of programs? i don't expect cryptic warnings when I compile Hello World.
Is it possible to silence this warning without passing the flag to the linker every time? An option in a config file hidden somewhere in c:\mingw, perhaps? Or maybe I missed an "automatically enable auto-import" checkbox during installation?
Possibly Relevant Specs
GCC Version 4.5.0
ld.exe Version 2.20.51.20100613
Windows XP Service Pack 3
I used to face same problem as you do with g++. I solved this irritating problem just now. Here is how I come to the solution, step-by-step:
On Windows, you can create an alias of g++ with all given options which you want to use with g++. Say, for example, you want to create an alias s++ of g++ -enable-auto-import, then you run this on cmd as:
C:\>doskey s++=g++ -enable-auto-import
This creates an alias called s++. But this alias will not take any command line argument, which means, you cannot write this:
C:\>s++ filename.cpp //it is not working
To make it work, if you've to tell the alias to accept command line arguments while creating it, so here is how it is done:
C:\>doskey s++=g++ -enable-auto-import $*
Please note the $* at the right, which indicates that now s++ can take command line argument:
C:\>s++ filename.cpp //yayyyy..its working now, without giving any warnings!
But you may not prefer to create the alias everytime you open cmd. In that case, you can create a shortcut of cmd.
For example, I created a shortcut called Console and in the Target textbox of shortcut window, I wrote this:
C:\WINDOWS\System32\cmd.exe /K doskey s++=g++ -enable-auto-import $*
And since this is too long (horizontally), one screenshot was not able to capture the entire command. I took two screenshots so that you could see yourself how I did it:
Left part of the command
Right part of the command
For more information on creating aliases on windows, see this:
Creating aliases on Windows
I did some reading and it looks like it might be related to the mingw32 dll not having dllimport attributes defined.
Perhaps there is a patch or you can rebuild mingw32 yourself and add them?

MinGW gcc C compiler works, but g++ does not

I'm a noob, I admit it. Regardless, I've had a really annoying problem with MinGW.... I can write AND compile programs in C with no problem whatsoever, but recently I've tried to install Cmake, but I can't because it fails every time it tests the C++ compiler (g++). So that lead me to just write a simple "hello world" program in C++ and try to compile it. No dice. Again and again I get no response whatsoever. On the command line, I'm typing
g++ -o hello++.cpp hello++
but have also tried
g++ -o hello++.cxx hello++
g++ -o hello++.cc hello++
g++ -o hello++ hello++.cpp
(Of course I saved copies of the source code in the same directory with the .cxx and .cc extensions respectively)
and a bunch of other combinations thereof. Everytime I get nothing. No warning. No error. Nothing. No .exe file was created in the directory, and typing "hello++" on the command line afterwards just gives me a "command not found" error. Soooo.... what the hell is going on? Why does the gcc command work but the g++ not?
I'm on windows 8, using cygwin.
The last one should have succeeded; you won't get a message saying it's succeeded, but you should see the executable in the current directory. The others all try to take the executable as input and output the source, which won't work; although I'm surprised you don't get error messages.
If it did succeed, then simply typing hello++ is unlikely to run it since the current directory is typically not on the path. Try ./hello++ instead.
If it didn't succeed, then it's possible that g++ isn't installed properly. I'm afraid I've no idea how to fix a broken Cygwin installation. Perhaps which g++, to see which program is actually being run, might give some clues.

Purpose of --enable-auto-import Warning

I am trying to compile the following program:
#include <iostream>
int main(){
std::cout << "Hello, world!";
return 0;
}
When I compile it, I get this message:
C:\programs>g++ test.cpp
Info: resolving std::cout by linking to __imp___ZSt4cout (auto-import)
c:/mingw/bin/../lib/gcc/mingw32/4.5.0/../../../../mingw32/bin/ld.exe: warning: a
uto-importing has been activated without --enable-auto-import specified on the c
ommand line.
This should work unless it involves constant data structures referencing symbols
from auto-imported DLLs.
The build succeeds and the executable runs as expected, but this warning still irritates me. I expect a successful build to be completely silent. This message gives the false impression that there's something wrong with my code.
I can silence this error with g++ -Xlinker --enable-auto-import test.cpp, but this is undesirable, as it triples the number of characters I need to type to compile a program.
Questions:
Why does this warning appear for the simplest of programs? i don't expect cryptic warnings when I compile Hello World.
Is it possible to silence this warning without passing the flag to the linker every time? An option in a config file hidden somewhere in c:\mingw, perhaps? Or maybe I missed an "automatically enable auto-import" checkbox during installation?
Possibly Relevant Specs
GCC Version 4.5.0
ld.exe Version 2.20.51.20100613
Windows XP Service Pack 3
I used to face same problem as you do with g++. I solved this irritating problem just now. Here is how I come to the solution, step-by-step:
On Windows, you can create an alias of g++ with all given options which you want to use with g++. Say, for example, you want to create an alias s++ of g++ -enable-auto-import, then you run this on cmd as:
C:\>doskey s++=g++ -enable-auto-import
This creates an alias called s++. But this alias will not take any command line argument, which means, you cannot write this:
C:\>s++ filename.cpp //it is not working
To make it work, if you've to tell the alias to accept command line arguments while creating it, so here is how it is done:
C:\>doskey s++=g++ -enable-auto-import $*
Please note the $* at the right, which indicates that now s++ can take command line argument:
C:\>s++ filename.cpp //yayyyy..its working now, without giving any warnings!
But you may not prefer to create the alias everytime you open cmd. In that case, you can create a shortcut of cmd.
For example, I created a shortcut called Console and in the Target textbox of shortcut window, I wrote this:
C:\WINDOWS\System32\cmd.exe /K doskey s++=g++ -enable-auto-import $*
And since this is too long (horizontally), one screenshot was not able to capture the entire command. I took two screenshots so that you could see yourself how I did it:
Left part of the command
Right part of the command
For more information on creating aliases on windows, see this:
Creating aliases on Windows
I did some reading and it looks like it might be related to the mingw32 dll not having dllimport attributes defined.
Perhaps there is a patch or you can rebuild mingw32 yourself and add them?

Issues compiling vmware web api client code into useable objects

I'm using vmware's web application api in an attempt just to simply retrieve the fields in the "ServiceContent" object. There is an example of how this should be accomplished located at the vmware forum. The example contained there compiles fine for me however I get segfaults when running the simple example - specifically the trace goes back to the soap_serializeheader() function (I believe these are defined in stdsoap2.cpp). My problem is that I do not know how to avoid this segfault and have no idea why this is occurring (as I am following the example almost word for word). I am using OS X tool chain (gcc version 4.0.1 (Apple Inc. build 5465) ) combined with (gsoap release 2.7.16). I tried gsoap 2.8 but got the same result. Below is the procedure I used to get to where I am now.
These are the commands I used to parse the wsdl:
wsdl2h -o vim25.h vimService.wsdl
Once this is parsed, I compiled using the following command:
soapcpp2 -x -C -pvsp vim25.h -I/place/where/stlvector.h/is
this generates files vspC.cpp, vspClient.cpp, and vspVimBindingProxy.cpp. Internally these files have the same prefixes for functions (i.e. ns1/ns2 etc) so my calls are the same as those in the example.
This is the command I am using to compile vspC.cpp and vspClient.cpp:
g++ -DWITH_COOKIES -DWITH_OPENSSL -c vspC.cpp
g++ -DWITH_COOKIES -DWITH_OPENSSL -c vspClient.cpp
This is the command I use to compile stdsoap2.cpp (if I do not compile with -DWITH_NONAMESPACES I get an error about an undefined symbol "_namepspaces" when I link everything):
g++ -DWITH_COOKIES -DWITH_OPENSSL -DWITH_NONAMESPACES -c stdsoap2.cpp
I then link everything together with the test code (again this is copied almost identically from the example, just with the changes to correctly refer to the files I created):
g++ -DWITH_COOKIES -DWITH_OPENSSL vspC.o vcpClient.o stdsoap2.o testcase.cpp -lssl -lcrypto -o doesntwork
This compiles correctly, but of course fails to run. I read about an OS X user in this vmware forum post who was also having trouble. It appears the gsoap guide says you cannot use stdsoap2.cpp's header and fault serialization codes, and you must compile them separately. The user in the OS X post seems to have done this, however I am not sure how to incorporate them into my test file (he creates the empty env.h file and then compiles it with soap2cpp) - if I include the envH.h file i get about naming conflicts with vspH.h. So a second question would be how do I use soap2cpp to compile all the stubs correctly so that there are not namespace conflicts (which is what I appear to be encountering).
I will not provide the source, as it is displayed at the first vwmare forum link by user stumpr. I do not believe the issue is in the source, but in the way I have used either wsdl2h, soap2cpp, or some incorrect combination of flags during compilation with g++.
Thanks for taking a look, and hopefully some one can resolve the issue!
EDIT I think I may have solved this - by using a 64bit system (and one with more memory). I tried compiling with -m32 on the X.6 and it was not able to do it (complaining about memory issues).
Hopefully someone will stumble upon this and be happy to know the answer.