Hello world compile error with stlport and Digital Mars - c++

I'm jumping into C++ and I've fallen at the first hurdle.
I've got a simple hello world:
// #include <iostream>
int main()
{
// std::cout <<"This actually works!" << std::endl;
return 0;
}
I can compile this with Digital Mars using
\dm\bin\dmc hello
However, if I uncomment the two lines and try to get the iostream to work with
\dm\bin\dmc hello -I\dm\stlport\stlport I get the following error:
template <int _Is> struct __bool2type {
^
\dm\stlport\stlport\stl/type_traits.h(68) : Error: '=', ';' or ',' expected
};
^
\dm\stlport\stlport\stl/type_traits.h(70) : Error: identifier or '( declarator )' expected
_STLP_TEMPLATE_NULL
^
\dm\stlport\stlport\stl/type_traits.h(72) : Error: '=', ';' or ',' expected
struct __bool2type<1> { typedef __true_type _Ret; };
^
\dm\stlport\stlport\stl/type_traits.h(73) : Error: identifier or '( declarator )' expected
_STLP_TEMPLATE_NULL
^
\dm\stlport\stlport\stl/type_traits.h(75) : Error: '=', ';' or ',' expected
Fatal error: too many errors
--- errorlevel 1`
I've put the extra stlport folder in dm\stlport\stlport
My SC.INI is as follows:
[Version]
version=7.51 Build 020
[Environment]
PATH=%PATH%;"%#P%\..\bin"
BIN="%#P%\..\bin"
INCLUDE="%#P%\..\stlport\stlport";"%#P%\..\include";"%#P%\..\mfc\include";%INCLUDE%
LIB="%#P%\..\lib";"%#P%\..\mfc\lib";%LIB%
HELP="%#P%\..\help"

Related

Getting an weird error in vscode when i'm trying to run a code

When I'm trying to run a simple hello world script it sends this error message, Can anyone help me solving this issue?
[Running] cd "c:\Users\NickT\OneDrive\Documents\C++ Tutorial\" && g++ helloworld.cpp -o helloworld && "c:\Users\NickT\OneDrive\Documents\C++ Tutorial\"helloworld
helloworld.cpp: In function `int main()':
helloworld.cpp:9: error: expected primary-expression before "msg"
helloworld.cpp:9: error: expected `;' before "msg"
helloworld.cpp:11: error: expected primary-expression before "const"
helloworld.cpp:11: error: expected `;' before "const"
helloworld.cpp:16: error: expected primary-expression before '}' token
helloworld.cpp:16: error: expected `)' before '}' token
helloworld.cpp:16: error: expected primary-expression before '}' token
helloworld.cpp:16: error: expected `;' before '}' token
[Done] exited with code=1 in 0.233 seconds
This is the written code
#include <iostream>
int main(){
std::cout << "Hello World" << std::endl;
return 0;
}
I revised the code you have posted as well as added a piece of code to utilize the namespace std. Analyzing the output from your compiler it does seem that you may have not added a semi colon. Alternatively, it's not necessary to reference the std library when calling it's functions but it's up to your preference. It doesn't seem though to be an issue with your code either. Can you post the actual code you've attempted to compile because there doesn't seem to be an issue with this piece.
Revised Code:
#include <iostream>
using namespace std;
int main() {
std::cout << "Hello World" << std::endl;
return 0;
}

rapidjson error: expected unqualified-id before 'bool' when building for Linux using Bazel

I'm compiling some C++ code that compiles fine for Android and iOS but fails under Linux. I've searched around and it looks like this kind of crash shows up when the implementer does something wrong; such as, using a reserved word. However I fail to see what I am doing wrong based on the error I'm getting.
In file included from external/rapidjson_artifact/include/rapidjson/document.h:20:0,
from src/main/cc/com/mycompany/serialization/JsonSerializer.h:4,
from bazel-out/k8-dbg/genfiles/src/main/java/com/mycompany/model/common/cc/com
/mycompany/model/common/Vector2d.h:13,
from bazel-out/k8-dbg/genfiles/src/main/java/com/mycompany/model/common/cc/com/mycompany/model/common/FastVector2d.h:10,
from src/main/cc/com/mycompany/api/gestures/primitives/CalculatedElementPosition.h:7,
from src/main/cc/com/mycompany/api/gestures/primitives/PointerInteraction.h:7,
from src/main/cc/com/mycompany/api/gestures/native/NativeUserInteractionHandler.h:10,
from src/main/cc/com/mycompany/linux/api/gestures/UserInteractionHandler.h:4,
from src/main/cc/com/mycompany/linux/api/opengl/OpenGlHandler.h:13,
from src/main/cc/com/mycompany/linux/api/opengl/OpenGlHandler.cc:1:
external/rapidjson_artifact/include/rapidjson/reader.h:189:15: error: expected unqualified-id before 'bool'
bool Bool(bool) { return static_cast<Override&>(*this).Default(); }
^~~~
external/rapidjson_artifact/include/rapidjson/reader.h:189:15: error: expected ')' before 'bool'
In file included from /usr/include/GL/glx.h:30:0,
from src/main/cc/com/mycompany/linux/api/opengl/OpenGlHandler.h:7,
from src/main/cc/com/mycompany/linux/api/opengl/OpenGlHandler.cc:1:
external/rapidjson_artifact/include/rapidjson/reader.h: In member function 'void rapidjson::GenericReader<SourceEncoding, TargetEncoding, StackAllocator>::ParseTrue(InputStream&, Handler&)':
external/rapidjson_artifact/include/rapidjson/reader.h:623:26: error: expected unqualified-id before 'int'
if (!handler.Bool(true))
^
external/rapidjson_artifact/include/rapidjson/reader.h:623:26: error: expected ')' before 'int'
external/rapidjson_artifact/include/rapidjson/reader.h: In member function 'void rapidjson::GenericReader<SourceEncoding, TargetEncoding, StackAllocator>::ParseFalse(InputStream&, Handler&)':
external/rapidjson_artifact/include/rapidjson/reader.h:636:26: error: expected unqualified-id before 'int'
if (!handler.Bool(false))
^
external/rapidjson_artifact/include/rapidjson/reader.h:636:26: error: expected ')' before 'int'
external/rapidjson_artifact/include/rapidjson/document.h: In member function 'bool rapidjson::GenericValue<Encoding, Allocator>::Accept(Handler&) const':
external/rapidjson_artifact/include/rapidjson/document.h:1539:44: error: expected unqualified-id before 'int'
case kFalseType: return handler.Bool(false);
^
external/rapidjson_artifact/include/rapidjson/document.h:1539:44: error: expected ';' before 'int'
external/rapidjson_artifact/include/rapidjson/document.h:1540:44: error: expected unqualified-id before 'int'
case kTrueType: return handler.Bool(true);
^
external/rapidjson_artifact/include/rapidjson/document.h:1540:44: error: expected ';' before 'int'
In file included from src/main/cc/com/mycompany/serialization/JsonSerializer.h:4:0,
from bazel-out/k8-dbg/genfiles/src/main/java/com/mycompany/model/common/cc/com/mycompany/model/common/Vector2d.h:13,
from bazel-out/k8-dbg/genfiles/src/main/java/com/mycompany/model/common/cc/com/mycompany/model/common/FastVector2d.h:10,
from src/main/cc/com/mycompany/api/gestures/primitives/CalculatedElementPosition.h:7,
from src/main/cc/com/mycompany/api/gestures/primitives/PointerInteraction.h:7,
from src/main/cc/com/mycompany/api/gestures/native/NativeUserInteractionHandler.h:10,
from src/main/cc/com/mycompany/linux/api/gestures/UserInteractionHandler.h:4,
from src/main/cc/com/mycompany/linux/api/opengl/OpenGlHandler.h:13,
from src/main/cc/com/mycompany/linux/api/opengl/OpenGlHandler.cc:1:
external/rapidjson_artifact/include/rapidjson/document.h: At global scope:
external/rapidjson_artifact/include/rapidjson/document.h:2028:15: error: expected unqualified-id before 'bool'
bool Bool(bool b) { new (stack_.template Push<ValueType>()) ValueType(b); return true; }
^~~~
external/rapidjson_artifact/include/rapidjson/document.h:2028:15: error: expected ')' before 'bool'
In file included from src/main/cc/com/mycompany/serialization/JsonSerializer.h:6:0,
from bazel-out/k8-dbg/genfiles/src/main/java/com/mycompany/model/common/cc/com/mycompany/model/common/Vector2d.h:13,
from bazel-out/k8-dbg/genfiles/src/main/java/com/mycompany/model/common/cc/com/mycompany/model/common/FastVector2d.h:10,
from src/main/cc/com/mycompany/api/gestures/primitives/CalculatedElementPosition.h:7,
from src/main/cc/com/mycompany/api/gestures/primitives/PointerInteraction.h:7,
from src/main/cc/com/mycompany/api/gestures/native/NativeUserInteractionHandler.h:10,
from src/main/cc/com/mycompany/linux/api/gestures/UserInteractionHandler.h:4,
from src/main/cc/com/mycompany/linux/api/opengl/OpenGlHandler.h:13,
from src/main/cc/com/mycompany/linux/api/opengl/OpenGlHandler.cc:1:
external/rapidjson_artifact/include/rapidjson/writer.h:109:15: error: expected unqualified-id before 'bool'
bool Bool(bool b) { Prefix(b ? kTrueType : kFalseType); return WriteBool(b); }
^~~~
external/rapidjson_artifact/include/rapidjson/writer.h:109:15: error: expected ')' before 'bool'
All the errors point to rapidjson but I highly doubt that is the problem. It is probably something I'm doing wrong.
Can someone suggest what I should look for to find the root cause?

How to call AWS CPP SDK functions from C [duplicate]

This question already has answers here:
How to call C++ function from C?
(7 answers)
Closed 3 years ago.
I am currently using the AWS CPP SDK for s3 and I am trying to call functions in my C++ files from a C file.
I have already looked up guides on how to call C++ functions from a C file, and I have done so successfully with simple, non-AWS functions. However, when I try and use the same guide to do so with an AWS CPP SDK function it does not work correctly. Below are the files and the commands I am running.
list_buckets.cpp
#include <stdio.h>
#include <aws/core/Aws.h>
#include <aws/s3/S3Client.h>
#include <aws/s3/model/Bucket.h>
using namespace std;
extern "C" {
void listBuckets();
}
void listBuckets() {
Aws::S3::S3Client s3_client;
auto outcome = s3_client.ListBuckets();
if (outcome.IsSuccess()) {
cout << "Your Amazon S3 buckets:" << endl;
Aws::Vector<Aws::S3::Model::Bucket> bucket_list = outcome.GetResult().GetBuckets();
for (auto const &bucket : bucket_list) {
cout << " * " << bucket.GetName() << endl;
}
} else {
cout << "ListBuckets error: " << outcome.GetError().GetExceptionName() << " - " << outcome.GetError().GetMessage() << endl;
}
}
int main(int argc, char const *argv[]) {
Aws::SDKOptions options;
Aws::InitAPI(options);
cout << "Listing buckets from list_buckets.cpp" << endl;
listBuckets();
Aws::ShutdownAPI(options);
return 0;
}
list_buckets.h
#include <aws/core/Aws.h>
void listBuckets();
list_buckets.c
#include "list_buckets.h"
int main(int argc, char const *argv[]) {
Aws::SDKOptions options;
Aws::InitAPI(options);
printf("Listing buckets from list_buckets.c\n");
listBuckets();
Aws::ShutdownAPI(options);
return 0;
}
To run list_buckets.cpp, I use g++ -std=c++17 -Wall -laws-cpp-sdk-core -laws-cpp-sdk-s3 list_buckets.cpp -o list_buckets && ./list_buckets, and the output is:
Your Amazon S3 buckets:
* bucket-name1
* bucket-name2
* bucket-name3
To build the library files for listing the AWS buckets, I run g++ -std=c++17 -laws-cpp-sdk-core -laws-cpp-sdk-s3 list_buckets.cpp -shared -o liblist_buckets.so.
To run list_buckets.c, I run gcc -I/Library/Developer/CommandLineTools/usr/include/c++/v1 -L. -llist_buckets list_buckets.c. However, it only produces errors which I have provided below.
In file included from list_buckets.c:1:
In file included from ./list_buckets.h:1:
In file included from /usr/local/include/aws/core/Aws.h:17:
In file included from /usr/local/include/aws/core/utils/logging/LogLevel.h:20:
In file included from /usr/local/include/aws/core/utils/memory/stl/AWSString.h:20:
In file included from /usr/local/include/aws/core/utils/memory/stl/AWSAllocator.h:21:
In file included from /usr/local/include/aws/core/utils/memory/AWSMemory.h:20:
In file included from /usr/local/include/aws/core/utils/memory/MemorySystemInterface.h:20:
/Library/Developer/CommandLineTools/usr/include/c++/v1/cstdlib:98:1: error: unknown type name '_LIBCPP_BEGIN_NAMESPACE_STD'
_LIBCPP_BEGIN_NAMESPACE_STD
^
/Library/Developer/CommandLineTools/usr/include/c++/v1/cstdlib:100:7: error: expected ';' after top level declarator
using ::size_t;
^
/Library/Developer/CommandLineTools/usr/include/c++/v1/cstdlib:100:8: error: expected identifier or '('
using ::size_t;
^
/Library/Developer/CommandLineTools/usr/include/c++/v1/cstdlib:101:7: error: expected ';' after top level declarator
using ::div_t;
^
/Library/Developer/CommandLineTools/usr/include/c++/v1/cstdlib:101:8: error: expected identifier or '('
using ::div_t;
^
/Library/Developer/CommandLineTools/usr/include/c++/v1/cstdlib:102:7: error: expected ';' after top level declarator
using ::ldiv_t;
^
/Library/Developer/CommandLineTools/usr/include/c++/v1/cstdlib:102:8: error: expected identifier or '('
using ::ldiv_t;
^
/Library/Developer/CommandLineTools/usr/include/c++/v1/cstdlib:104:7: error: expected ';' after top level declarator
using ::lldiv_t;
^
/Library/Developer/CommandLineTools/usr/include/c++/v1/cstdlib:104:8: error: expected identifier or '('
using ::lldiv_t;
^
/Library/Developer/CommandLineTools/usr/include/c++/v1/cstdlib:106:7: error: expected ';' after top level declarator
using ::atof;
^
/Library/Developer/CommandLineTools/usr/include/c++/v1/cstdlib:106:8: error: expected identifier or '('
using ::atof;
^
/Library/Developer/CommandLineTools/usr/include/c++/v1/cstdlib:107:7: error: expected ';' after top level declarator
using ::atoi;
^
/Library/Developer/CommandLineTools/usr/include/c++/v1/cstdlib:107:8: error: expected identifier or '('
using ::atoi;
^
/Library/Developer/CommandLineTools/usr/include/c++/v1/cstdlib:108:7: error: expected ';' after top level declarator
using ::atol;
^
/Library/Developer/CommandLineTools/usr/include/c++/v1/cstdlib:108:8: error: expected identifier or '('
using ::atol;
^
/Library/Developer/CommandLineTools/usr/include/c++/v1/cstdlib:110:7: error: expected ';' after top level declarator
using ::atoll;
^
/Library/Developer/CommandLineTools/usr/include/c++/v1/cstdlib:110:8: error: expected identifier or '('
using ::atoll;
^
/Library/Developer/CommandLineTools/usr/include/c++/v1/cstdlib:112:7: error: expected ';' after top level declarator
using ::strtod;
^
/Library/Developer/CommandLineTools/usr/include/c++/v1/cstdlib:112:8: error: expected identifier or '('
using ::strtod;
^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make: *** [executeListBucketsLib] Error 1
I am stuck on how to resolve this issue. Any and all help/guidance is greatly appreciated.
Change list_buckets.h
#include <aws/core/Aws.h>
extern "C" {
void listBuckets();
}
This tells the C compiler what the linking syntax is. This affects the function naming scheme that the linker uses to resolve symbols.

STL vector error: Unknown type name

I have this structure:
struct casilla{
int x,y;
};
And these lines of code;
std::vector<std::vector<std::vector<casilla> > > iniciales;
iniciales.resize(7);
Wich give me this error in the g++ compiler:
src/tetromino.cpp:5:1: error: unknown type name 'iniciales'
iniciales.resize(7);
^
src/tetromino.cpp:5:10: error: expected unqualified-id
iniciales.resize(7);
Edit: I modified my code and now it's like this:
std::vector<std::vector<std::vector<casilla> > > iniciales(7);
for(int i=0; i<iniciales.size();i++){
iniciales[i].resize(3);
for(int i=0; i<3;i++)
iniciales[i][j].resize(4);
}
iniciales.at(TTR_CUADRADO){{{0,5},{0,6},{1,5},{1,6}}};
iniciales.at(TTR_LREVES)={{ {0,4},{0,5},{0,6},{1,6} },
{{-1,5},{0,5},{1,5},{1,4}},
{{0,4},{1,4},{1,5},{1,6}},
{{-1,5},{-1,6},{0,5},{1,5}}
};
iniciales.at(TTR_L)={{{0,4}{0,5},{0,6},{1,4}},{{-1,5},{0,5},{1,5},{1,6}},
{{0,4},{0,5},{0,6},{-1,6}},{{-1,4},{-1,5},{0,5},{1,5}}};
iniciales.at(TTR_Z)={{{0,5},{0,6},{1,6},{1,7}},{{0,6},{1,6},{0,7},{-1,7},}};
iniciales.at(TTR_ZREVES)={{{0,6},{0,7},{1,5},{1,6}},{{0,6},{0,7},{-1,6},{1,7}}};
iniciales.at(TTR_I)={{{0,4},{0,5},{0,6},{0,7}},{{-2,6},{-1,6},{0,6},{1,6}}};
iniciales.at(TTR_T)={{{0,5},{0,6},{0,7},{1,6}}}
for(int i=0; i<iniciales.size();i++){
for(int i=0; i<3;i++)
iniciales[i][j].shrink_to_fit();
}
}
All the TTR* variables are enumerated values between 0 and 6.
This is when the party starts:
c++ -Wall -g -Iinclude -c src/tetromino.cpp -o obj/tetromino.o
src/tetromino.cpp:5:1: error: expected unqualified-id
for(int i=0; i<iniciales.size();i++){
^
src/tetromino.cpp:10:2: error: unknown type name 'iniciales'
iniciales.at(TTR_CUADRADO){{{0,5},{0,6},{1,5},{1,6}}};
^
src/tetromino.cpp:10:11: error: expected unqualified-id
iniciales.at(TTR_CUADRADO){{{0,5},{0,6},{1,5},{1,6}}};
^
src/tetromino.cpp:11:1: error: unknown type name 'iniciales'
iniciales.at(TTR_LREVES)={{ {0,4},{0,5},{0,6},{1,6} },
^
src/tetromino.cpp:11:10: error: expected unqualified-id
iniciales.at(TTR_LREVES)={{ {0,4},{0,5},{0,6},{1,6} },
^
src/tetromino.cpp:16:1: error: unknown type name 'iniciales'
iniciales.at(TTR_L)={{{0,4}{0,5},{0,6},{1,4}},{{-1,5},{0,5},{1,5},{1,6}},
^
src/tetromino.cpp:16:10: error: expected unqualified-id
iniciales.at(TTR_L)={{{0,4}{0,5},{0,6},{1,4}},{{-1,5},{0,5},{1,5},{1,6}},
^
src/tetromino.cpp:18:1: error: unknown type name 'iniciales'
iniciales.at(TTR_Z)={{{0,5},{0,6},{1,6},{1,7}},{{0,6},{1,6},{0,7},{-1,7},}};
^
src/tetromino.cpp:18:10: error: expected unqualified-id
iniciales.at(TTR_Z)={{{0,5},{0,6},{1,6},{1,7}},{{0,6},{1,6},{0,7},{-1,7},}};
^
src/tetromino.cpp:19:1: error: unknown type name 'iniciales'
iniciales.at(TTR_ZREVES)={{{0,6},{0,7},{1,5},{1,6}},{{0,6},{0,7},{-1,6},{1,7}}};
^
src/tetromino.cpp:19:10: error: expected unqualified-id
iniciales.at(TTR_ZREVES)={{{0,6},{0,7},{1,5},{1,6}},{{0,6},{0,7},{-1,6},{1,7}}};
^
src/tetromino.cpp:20:1: error: unknown type name 'iniciales'
iniciales.at(TTR_I)={{{0,4},{0,5},{0,6},{0,7}},{{-2,6},{-1,6},{0,6},{1,6}}};
^
src/tetromino.cpp:20:10: error: expected unqualified-id
iniciales.at(TTR_I)={{{0,4},{0,5},{0,6},{0,7}},{{-2,6},{-1,6},{0,6},{1,6}}};
^
src/tetromino.cpp:21:1: error: unknown type name 'iniciales'
iniciales.at(TTR_T)={{{0,5},{0,6},{0,7},{1,6}}}
^
src/tetromino.cpp:21:10: error: expected unqualified-id
iniciales.at(TTR_T)={{{0,5},{0,6},{0,7},{1,6}}}
^
src/tetromino.cpp:22:1: error: expected unqualified-id
for(int i=0; i<iniciales.size();i++){
^
src/tetromino.cpp:26:1: error: extraneous closing brace ('}')
}
^
src/tetromino.cpp:27:1: error: no template named 'vector'; did you mean
'std::vector'?
vector<casilla> tetromino::Zonstd::aComun(vector<casillstd::a> v1,...
^~~~~~
std::vector
/usr/include/c++/4.2.1/bits/stl_vector.h:162:11: note: 'std::vector' declared
here
class vector : protected _Vector_base<_Tp, _Alloc>
^
src/tetromino.cpp:27:28: error: no member named 'Zonstd' in 'tetromino'
vector<casilla> tetromino::Zonstd::aComun(vector<casillstd::a> v1,...
~~~~~~~~~~~^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
What should I do?
As #Jack is saying, i think it could be because I'm doind it outside any method. Should i make an specific method to set this global variable. Also I prefer to make a global variable rather than creating one each time I call a function.
PS.:Sorry for the "weird" variable names, I'm programming in Spanish. :P
My guess is that you are trying to execute some code outside of a method, eg:
#include <vector>
std::vector<std::vector<std::vector<casilla> > > iniciales;
iniciales.resize(7);
while it should be
#include <vector>
std::vector<std::vector<std::vector<casilla> > > iniciales;
void someMethod() {
iniciales.resize(7);
}
or, even better:
std::vector<std::vector<std::vector<casilla> > > iniciales(7);

C++ expected `)' before ';' token expected primary-expression before ')' token

Hello there I am iplementingh a binary tree based on an underlying array.
My project is comprises a set of c++ files and the makefile for generating the compilation.
I am using g++ provided with DEV-C++ 4.9.9.2.
Upon launching compilation I get the following two set of errors.
AlberoBinariov.h: In member function bool AlberoBinariov<T>::figlioSinistroVuoto(typename Alberoa<T, int>::posizioneNodo)':
AlberoBinariov.h:198: error: expected)' before ';' token
AlberoBinariov.h:198: error: expected primary-expression before ')' token
AlberoBinariov.h:198: error: expected `;' before ')' token
AlberoBinariov.h: In member function bool AlberoBinariov<T>::figlioDestroVuoto(typename Alberoa<T, int>::posizioneNodo)':
AlberoBinariov.h:204: error: expected)' before ';' token
AlberoBinariov.h:204: error: expected )' before ';' token
AlberoBinariov.h:204: error: expected primary-expression before ')' token
AlberoBinariov.h:204: error: expected;' before ')' token
Interested portions of code are provided below:
template <class T>
bool AlberoBinariov<T>::figlioSinistroVuoto(posizioneNodo p)
{
return (figlioSinistro(p)==(posizioneNodo)P_NULL); //line 198
}
template <class T>
bool AlberoBinariov<T>::figlioDestroVuoto(posizioneNodo p)
{
return (figlioDestro(p)==((posizioneNodo)P_NULL)); //line 204
}
also for your convenince I have included the full source code at the link below.
https://filetea.me/t1sc3e60
Can you please let me know? thanks you in advance for your time. I look forward to hear from you.
Kind regards,
Gerald
PS: P_NULL is a NULL pointer constant declared in the Constants.h file.
You have 3 individual right parenthesis without their corresponding left parenthesis:
return (figlioDestro(p) == ((posizioneNodo)P_NULL)) /* -> */ )));
Change it to this:
return (figlioDestro(p) == ( (posizioneNodo)P_NULL ));