Errors from running code compiled by gcc












0















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.










share|improve this question







New contributor




armand de bruijn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





















  • 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


















0















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.










share|improve this question







New contributor




armand de bruijn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





















  • 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
















0












0








0








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.










share|improve this question







New contributor




armand de bruijn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












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






share|improve this question







New contributor




armand de bruijn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question







New contributor




armand de bruijn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question






New contributor




armand de bruijn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 6 hours ago









armand de bruijnarmand de bruijn

1




1




New contributor




armand de bruijn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





armand de bruijn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






armand de bruijn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.













  • 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











  • 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












1 Answer
1






active

oldest

votes


















0














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 #includeed. 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





share|improve this answer























    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.










    draft saved

    draft discarded


















    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









    0














    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 #includeed. 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





    share|improve this answer




























      0














      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 #includeed. 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





      share|improve this answer


























        0












        0








        0







        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 #includeed. 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





        share|improve this answer













        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 #includeed. 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






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 25 mins ago









        steeldriversteeldriver

        68.9k11113184




        68.9k11113184






















            armand de bruijn is a new contributor. Be nice, and check out our Code of Conduct.










            draft saved

            draft discarded


















            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            GameSpot

            connect to host localhost port 22: Connection refused

            Getting a Wifi WPA2 wifi connection