LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-19-2019, 02:15 PM   #1
scooterboy
LQ Newbie
 
Registered: Aug 2019
Posts: 7

Rep: Reputation: Disabled
Compiling Programs With G++


Dear Linux Users:
Some weeks ago I started using Lubuntu 18.04, 64 bit. I installed
Code:Blocks and Allegro5 and Opengl. After compiling a program I went
to the directory where the executable was placed and clicked on it.
Linux ask what program I wanted to use to open it. Never got it to run.
I noticed that there was a question mark on the file. Never seen this
before. I then decided to compile the file from the command line. Same
problem. When using Code:blocks the file runs fine as long as I stay in
Code:Blocks. It also seems to compile fine using the command line!
I am using Code:Blocks version 16.01.
In the past I run all my programs on a 32 bit computer with Code:Blocks
version 13.12 and everything runs fine from the directory. The 64 bit
machine is where I see the problem. Can anyone help me?
Thanks for your help and everyone have a great day!
Talk to you later!
 
Old 08-19-2019, 02:52 PM   #2
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,883
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Welcome to LQ scooterboy,

I'm assuming that you've tried a very fundamental "hello world" style or program and not something very complicated?

I wonder if what your compile result is, will work on a 32-bit system.

Perhaps the project, or settings you have should be adjusted to recognize 64-bit environments. Not sure, just some guesses.

For the first hello world test, I'd create an entirely new project on the new install/system, to see if that works. Once again, if you already haven't tried this.
 
Old 08-19-2019, 03:27 PM   #3
scooterboy
LQ Newbie
 
Registered: Aug 2019
Posts: 7

Original Poster
Rep: Reputation: Disabled
rtmistler:

Thanks for the reply. I did a quick helloworld.cpp program and the same thing happened.
It compiled fine, but there is a question mark on the file in the directory. It will not open.

Here is the file:

#include <iostream>
int main()
{
std::cout << "Hello, World!";
return 0;
}

This is how it was compiled:

g++ helloworld.cpp -o hello


I have been compiling C and C++ files off and on for years but NEVER seen this.

I got my start back in the days of Borland Turbo C.

A real mystery for sure. It has to be something with the 64 bit but I can't figure it out.

This is my first experience with 64 bit and may be my last!
 
Old 08-19-2019, 05:08 PM   #4
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,883
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Does it show as executable?

Do you get errors trying to run it on the command line? If so, what are they?

I've used 64-bit gcc on c programs for years, unsure what the issue is here.

What also is the output of g++ --version ?
 
Old 08-19-2019, 05:31 PM   #5
scooterboy
LQ Newbie
 
Registered: Aug 2019
Posts: 7

Original Poster
Rep: Reputation: Disabled
rtmistler:
Thanks for the reply.

Does it show as executable:
Here is how the permissions are shown:

execute: Anyone

no errors from command line

output from g++ --version:

g++ (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
Old 08-19-2019, 08:09 PM   #6
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,883
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
What exactly does an ls -l of the file show?

No errors on command line? Did it print the output?
 
Old 08-20-2019, 06:04 AM   #7
scooterboy
LQ Newbie
 
Registered: Aug 2019
Posts: 7

Original Poster
Rep: Reputation: Disabled
rtmistler:

Hello, results from ls -l:

-rwxrwxr-x 1 scott scott 8776 Aug 19 16:11 hello

There were no errors on command line.

Did not print anything on output.
 
Old 08-20-2019, 07:02 AM   #8
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
Quote:
Originally Posted by scooterboy View Post
Dear Linux Users:
Some weeks ago I started using Lubuntu 18.04, 64 bit. I installed
Code:Blocks and Allegro5 and Opengl. After compiling a program I went
to the directory where the executable was placed and clicked on it.

Linux ask what program I wanted to use to open it. Never got it to run.
I noticed that there was a question mark on the file. Never seen this
before. I then decided to compile the file from the command line. Same
problem. When using Code:blocks the file runs fine as long as I stay in
Code:Blocks. It also seems to compile fine using the command line!
I am using Code:Blocks version 16.01.
In the past I run all my programs on a 32 bit computer with Code:Blocks
version 13.12 and everything runs fine from the directory. The 64 bit
machine is where I see the problem. Can anyone help me?
Thanks for your help and everyone have a great day!
Talk to you later!
clicked on it and it did not run...

1. write some code
2. compile same code
3 run the executable from that code.
Code:
./a.out <-- executable name aka program name using the ./ for current dir.
oh, that's in a terminal btw.

Last edited by BW-userx; 08-20-2019 at 07:04 AM.
 
1 members found this post helpful.
Old 08-20-2019, 07:27 AM   #9
scooterboy
LQ Newbie
 
Registered: Aug 2019
Posts: 7

Original Poster
Rep: Reputation: Disabled
BW-userx:

OK that does indeed work.

If I compile with Code:Blocks the same executable file will have a
question mark on it. Does that mean I will have to run the executable
from the command line? Never had to do that before.
 
Old 08-20-2019, 07:38 AM   #10
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
Quote:
Originally Posted by scooterboy View Post
BW-userx:

OK that does indeed work.

If I compile with Code:Blocks the same executable file will have a
question mark on it. Does that mean I will have to run the executable
from the command line? Never had to do that before.
to keep it short in linux (*nixs) command line execution is it. This is not windows. click and run.

I do not know this ? mark on it thing. ? means system does not know what it is.

when you say ? on it.. that tells me something is wrong. how may files is your program so far, if it is only one or two try using your cli to compile it then see what it does.
it's pretty straight forward for one or two files.

Code:
#include <iostream>

int main()
{
  std::cout << " HEY world..."<<std::endl;

return 0;
}

...
c++ main.cpp

..........

ls -la 

-rwxr-xr-x   1 userx  userx     30016 Aug 20 07:34 a.out

..........


[userx@FreeBSD64ssd ~]$ ./a.out
 HEY world...
I'm on FreeBSD they use 'c++' and Linux uses 'g++' that is just the naming scheme of that program, no big deal. default output program name is a.out, if no name is given.

that is how it is done in Unix based, or just Unix, even before Windows even knew of itself.

you hello
Quote:
Hello, results from ls -l:

-rwxrwxr-x 1 scott scott 8776 Aug 19 16:11 hello
try
Code:
./hello
it needs the absolute path to your program because it is not in the system PATH area.
./ <-- is the shortcut way of telling system the path to program when in the same dir the program is in.

echo $PATH

Last edited by BW-userx; 08-20-2019 at 07:51 AM.
 
1 members found this post helpful.
Old 08-20-2019, 07:38 AM   #11
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,883
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
@scooterboy,

I'm in front of a Linux terminal now. I have 64-bit Linux, and have had it for numerous years, I've lost count. I also have version 7.4.0 of the g++ compiler.

Your program works perfect. It compiles using the example line you've shown and it executes from the command line.

One final suggestion is to try GDB. Add -ggdb to your compile line, once completed, enter gdb with the resultant executable, set a breakpoint for line 5, the "cout" line, run it, see it hit the breakpoint, continue, and watch it complete, as well as print the output. If it can't/won't do that, or doesn't recognize any line of your source file, then seems something is wrong.

I'd recommend uninstall/re-install of your gcc toolset. Try uninstalling build-essential and re-installing it. That package contains the whole suite of tools for both C and C++ compiling.

By the way, you started all this discussing Code:Blocks, Allegro5, and Opengl. This gave me the impression that you have a project which you are building through and IDE. Hence why I recommended the course of just trying a hello world cpp file on the command line.

But given that you cannot successfully build and run on the command line, I feel there is something wrong with your install. Forget all the other libraries, environments, or tools. But I may opine that if these other libraries or tools installed "stuff" over your existing build-essential package, they may have corrupted it. Clearly your version of g++ is fine, and it matches my version word for word. But still, if one cannot do a simple compile of the most simple program, then something is wrong. The test with gdb is the best I have at this point.

Edit: And a *thing* which could be wrong could be that other environments or tools wrote over your standard libraries. That would seem to be an explanation. Maybe look at the output of "ldd hello" and see where the libraries the resultant binary is pointing to are located, if they seem to shows paths related to any of these other software packages you have installed, then that may be the key indicator which is causing you this grief. It also may be that one of those packages you installed is not 64-bit ready.

Last edited by rtmistler; 08-20-2019 at 07:42 AM.
 
Old 08-20-2019, 08:48 AM   #12
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,901

Rep: Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318
Quote:
Originally Posted by scooterboy View Post
rtmistler:

Hello, results from ls -l:

-rwxrwxr-x 1 scott scott 8776 Aug 19 16:11 hello

There were no errors on command line.

Did not print anything on output.
did you try to execute that hello program? Did it print anything (or nothing?).

In general would be nice to explain better what did you try exactly and what happened exactly. Dropping in statements like above is a bit confusing.
From the other hand it is definitely not related to 32/64 bit, but something else.

Also would be nice to explain this a bit better: It compiled fine, but there is a question mark on the file in the directory. It will not open.
How did you try [to compile], how did you check [if that was successful], where is that question mark exactly, what do you mean by "will not open"?
 
1 members found this post helpful.
Old 08-20-2019, 09:49 AM   #13
scooterboy
LQ Newbie
 
Registered: Aug 2019
Posts: 7

Original Poster
Rep: Reputation: Disabled
OK, I did another test. Maybe this will help.

I changed the name of my Hello program. Loaded it into Code:Blocks
and the file ran fine. I went to the directory and the executable
had the question mark just like the other files. Would NOT open.
I then opened the terminal and the file runs fine from the terminal.

Last weekend I decided to format the drive and load everything again.
I ended up with the same problem. I have all my programs on another
computer drive and wanted to move them to this new system. It has
Ubuntu 14.04 32 bit on this drive with over 92,000 files and it works
perfect.

On another note: On Lubuntu 18.04 you can go to the directory, under
the Tools Menu there is the option 'Run a Command in Current Folder'.
If you click on this option you get another window to enter the command.
I typed in the program name, clicked OK and got this message:

Failed to execute child process
"helloworldx" (No such file or directory)

How about that, Program Manager doesn't even know the file exists, but yet
I can run it from the terminal! What in the world is going on?????????

Thanks much for all the replies. This seems to be a problem for the books.
 
Old 08-20-2019, 10:02 AM   #14
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,883
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Stop testing this using the File manager, and IDE, or from within a graphical window.

helloworldx is not your output, the output is "hello" as specified by the command line:
Code:
g++ helloworld.cpp -o hello
And by the way, at one point you mentioned a.out. That's only if you didn't specify the -o argument.

So ... sorry for asking, you've said you've programmed for years.

How good/bad are you at Linux command prompt commands as well as using GCC and G++ directly from the command line? It seems as if you're making total newbie errors here, but haven't been assuming this all along.

You write a file, helloworld.cpp, the example you provided was fine. Side note, please learn how to use [code] blocks to enclose your code. That's how it makes things in another box and preserves formatting as part of it.

Next, you demonstrated the command line to compile it correctly, thus generating an output file named "hello", so to run it from there you type ./hello{return} and it runs.

Sorry this is all I have, trying to use windows from the file manager or an IDE to try and run a simple command line program is not my object here to aid with debugging.

Last edited by rtmistler; 08-20-2019 at 10:52 AM. Reason: fixed objection to object
 
Old 08-20-2019, 10:12 AM   #15
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,901

Rep: Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318
Quote:
Originally Posted by scooterboy View Post
How about that, Program Manager doesn't even know the file exists, but yet
I can run it from the terminal! What in the world is going on?????????
Because there are rules about how to find an executable and most probably your file is just out of scope. Program Manager has no any idea where to find it.

Quote:
Originally Posted by scooterboy View Post
This seems to be a problem for the books.
Which books?

You still did not answer and did not explain what did you try properly - hard to help you without those important details.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Programs installed with package manager aren't recognised by other programs fraserm Linux - Software 3 04-21-2007 12:38 PM
Are these programs - or equivalent programs - available for Linux? voly Linux - Software 12 07-29-2005 02:44 AM
my table with programs when i press in button (left down corner) do no show programs sagi7ario Mandriva 1 03-12-2004 12:02 PM
unable to add programs from add/remove programs dav7500 Linux - Software 2 02-26-2004 07:25 PM
How to get newly installed programs in programs list Brosky Linux - Software 5 02-06-2004 03:45 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:02 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration