Errors from running code compiled by gcc
So I just installed Ubuntu 18.04 on my (not so shiny) new thinkpad and I'm loving it, especially the new GNOME getup.
So I was looking to run some c++ code. Seems gcc is already installed by default so I try out a simple hello world program called test.cpp
I compile it: cpp test.cpp -o test
... works fine no errors.
I then try to run it but it says permission denied, so I do a quick chmod u+x
and it seems to at least try to run the program. No matter what code I put in and compile, it always comes with these errors:
./test: line 18: namespace: command not found
./test: line 22: syntax error near unexpected token `('
./test: line 22: ` typedef decltype(nullptr) nullptr_t;'
--Also note that there are only 7 lines of code and it gives me an error for line 18+?! Also why is it giving me errors after I compiled it?!
So I made a new account on #askubuntu and here I am now.
18.04 compiling gcc
New contributor
add a comment |
So I just installed Ubuntu 18.04 on my (not so shiny) new thinkpad and I'm loving it, especially the new GNOME getup.
So I was looking to run some c++ code. Seems gcc is already installed by default so I try out a simple hello world program called test.cpp
I compile it: cpp test.cpp -o test
... works fine no errors.
I then try to run it but it says permission denied, so I do a quick chmod u+x
and it seems to at least try to run the program. No matter what code I put in and compile, it always comes with these errors:
./test: line 18: namespace: command not found
./test: line 22: syntax error near unexpected token `('
./test: line 22: ` typedef decltype(nullptr) nullptr_t;'
--Also note that there are only 7 lines of code and it gives me an error for line 18+?! Also why is it giving me errors after I compiled it?!
So I made a new account on #askubuntu and here I am now.
18.04 compiling gcc
New contributor
If your test is really c++ code, you should install and use the g++ compiler, not the gcc compiler.
– ubfan1
6 hours ago
oh sorry by gcc I meant the gcc compiler collection which is pre-installed on Ubuntu, to actually compile the code I used cpp which is part of gcc
– armand de bruijn
3 hours ago
Yes I see what you mean, but I can assure you that i typed the command ./test rather than ./test.cpp. @steeldriver
– armand de bruijn
3 hours ago
add a comment |
So I just installed Ubuntu 18.04 on my (not so shiny) new thinkpad and I'm loving it, especially the new GNOME getup.
So I was looking to run some c++ code. Seems gcc is already installed by default so I try out a simple hello world program called test.cpp
I compile it: cpp test.cpp -o test
... works fine no errors.
I then try to run it but it says permission denied, so I do a quick chmod u+x
and it seems to at least try to run the program. No matter what code I put in and compile, it always comes with these errors:
./test: line 18: namespace: command not found
./test: line 22: syntax error near unexpected token `('
./test: line 22: ` typedef decltype(nullptr) nullptr_t;'
--Also note that there are only 7 lines of code and it gives me an error for line 18+?! Also why is it giving me errors after I compiled it?!
So I made a new account on #askubuntu and here I am now.
18.04 compiling gcc
New contributor
So I just installed Ubuntu 18.04 on my (not so shiny) new thinkpad and I'm loving it, especially the new GNOME getup.
So I was looking to run some c++ code. Seems gcc is already installed by default so I try out a simple hello world program called test.cpp
I compile it: cpp test.cpp -o test
... works fine no errors.
I then try to run it but it says permission denied, so I do a quick chmod u+x
and it seems to at least try to run the program. No matter what code I put in and compile, it always comes with these errors:
./test: line 18: namespace: command not found
./test: line 22: syntax error near unexpected token `('
./test: line 22: ` typedef decltype(nullptr) nullptr_t;'
--Also note that there are only 7 lines of code and it gives me an error for line 18+?! Also why is it giving me errors after I compiled it?!
So I made a new account on #askubuntu and here I am now.
18.04 compiling gcc
18.04 compiling gcc
New contributor
New contributor
New contributor
asked 6 hours ago
armand de bruijnarmand de bruijn
1
1
New contributor
New contributor
If your test is really c++ code, you should install and use the g++ compiler, not the gcc compiler.
– ubfan1
6 hours ago
oh sorry by gcc I meant the gcc compiler collection which is pre-installed on Ubuntu, to actually compile the code I used cpp which is part of gcc
– armand de bruijn
3 hours ago
Yes I see what you mean, but I can assure you that i typed the command ./test rather than ./test.cpp. @steeldriver
– armand de bruijn
3 hours ago
add a comment |
If your test is really c++ code, you should install and use the g++ compiler, not the gcc compiler.
– ubfan1
6 hours ago
oh sorry by gcc I meant the gcc compiler collection which is pre-installed on Ubuntu, to actually compile the code I used cpp which is part of gcc
– armand de bruijn
3 hours ago
Yes I see what you mean, but I can assure you that i typed the command ./test rather than ./test.cpp. @steeldriver
– armand de bruijn
3 hours ago
If your test is really c++ code, you should install and use the g++ compiler, not the gcc compiler.
– ubfan1
6 hours ago
If your test is really c++ code, you should install and use the g++ compiler, not the gcc compiler.
– ubfan1
6 hours ago
oh sorry by gcc I meant the gcc compiler collection which is pre-installed on Ubuntu, to actually compile the code I used cpp which is part of gcc
– armand de bruijn
3 hours ago
oh sorry by gcc I meant the gcc compiler collection which is pre-installed on Ubuntu, to actually compile the code I used cpp which is part of gcc
– armand de bruijn
3 hours ago
Yes I see what you mean, but I can assure you that i typed the command ./test rather than ./test.cpp. @steeldriver
– armand de bruijn
3 hours ago
Yes I see what you mean, but I can assure you that i typed the command ./test rather than ./test.cpp. @steeldriver
– armand de bruijn
3 hours ago
add a comment |
1 Answer
1
active
oldest
votes
cpp
is the C pre-processor - it is not a compiler. Its output is a text file containing expanded macros and declarations from any files that your code has #include
ed. When you made it executable and tried to run it, your shell made an attempt to interpret this text as shell code - and failed.
To compile your C++ file (and link into an executable) you should use g++
instead:
g++ test.cpp -o test
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
armand de bruijn is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1125126%2ferrors-from-running-code-compiled-by-gcc%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
cpp
is the C pre-processor - it is not a compiler. Its output is a text file containing expanded macros and declarations from any files that your code has #include
ed. When you made it executable and tried to run it, your shell made an attempt to interpret this text as shell code - and failed.
To compile your C++ file (and link into an executable) you should use g++
instead:
g++ test.cpp -o test
add a comment |
cpp
is the C pre-processor - it is not a compiler. Its output is a text file containing expanded macros and declarations from any files that your code has #include
ed. When you made it executable and tried to run it, your shell made an attempt to interpret this text as shell code - and failed.
To compile your C++ file (and link into an executable) you should use g++
instead:
g++ test.cpp -o test
add a comment |
cpp
is the C pre-processor - it is not a compiler. Its output is a text file containing expanded macros and declarations from any files that your code has #include
ed. When you made it executable and tried to run it, your shell made an attempt to interpret this text as shell code - and failed.
To compile your C++ file (and link into an executable) you should use g++
instead:
g++ test.cpp -o test
cpp
is the C pre-processor - it is not a compiler. Its output is a text file containing expanded macros and declarations from any files that your code has #include
ed. When you made it executable and tried to run it, your shell made an attempt to interpret this text as shell code - and failed.
To compile your C++ file (and link into an executable) you should use g++
instead:
g++ test.cpp -o test
answered 25 mins ago
steeldriversteeldriver
68.9k11113184
68.9k11113184
add a comment |
add a comment |
armand de bruijn is a new contributor. Be nice, and check out our Code of Conduct.
armand de bruijn is a new contributor. Be nice, and check out our Code of Conduct.
armand de bruijn is a new contributor. Be nice, and check out our Code of Conduct.
armand de bruijn is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Ask Ubuntu!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1125126%2ferrors-from-running-code-compiled-by-gcc%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
If your test is really c++ code, you should install and use the g++ compiler, not the gcc compiler.
– ubfan1
6 hours ago
oh sorry by gcc I meant the gcc compiler collection which is pre-installed on Ubuntu, to actually compile the code I used cpp which is part of gcc
– armand de bruijn
3 hours ago
Yes I see what you mean, but I can assure you that i typed the command ./test rather than ./test.cpp. @steeldriver
– armand de bruijn
3 hours ago