I'm not new to C++, but I just recently decided to switch to Linux (Windows 8 sucks...) and I'm having trouble running compiled programs.
Is there any recommended way to build them? Also, I can't seem to run the binaries... They are 64 bit (i am running 64 bit architecture)... I can't figure this out and I've searched google for the answer far and wide. (it reads: "Cannot execute binary file!")
So far, It seems that the binary won't initiate it's own command-line based terminal, like shells, and so I guess using the system() function (forbidden on Windows) is not such a security hole? Anyway...
I would like to start porting some programs, so I need some function equivilants (I tried to find them...):
-conio.h (if needed, was told I do not, and Ncurses is too bloated for my needs, unless you can tell me how to clear the screen without initiating the whole graphics)
-windows.h: Specifically- filesystem operations, time/date, and color(if no Ncurses)
Also, should I link statically or Dymaically? If statically, how can I link statically?
I think you can still build and run 32bit programs while on 64bit OS.
Also, system() should be avoided on ANY platform.
Linux's drawing system is different from windows's.
Windows has its own headers for drawing, playing sounds and so on.
Linux uses X11 for drawing, has different devices and drivers for audio and so on again.
As you may understand there's no 1:1 equivalent.
You should seriously use Ncurses while on linux tho.
Linking dynamically/statically is not an issue you should take into account right now, and i'm almost sure you can ONLY link dynamically.
Dependencies will be (probably) downloaded while installing it, and they will be placed in a shared system directory.
#/bin/sh
echo compiling C++ using program -pedantic-errors -Wall
g++ -o program -pedantic-errors -Wall $1 $2 $3
calling of the shell:
gccp main.cpp common.cpp common.h
and I end up with a binary.
Also, I have tried PDcurses... I hated it. I was more like a graphics library than a basic input/output library. Can you tell me how I can use it without usng the whole darn thing, or do I have to learn how to initiate windows, panels, blablabla... (in other words, learn all of it...)?
when I try to run the new binary (it's properties say that it can be executed) through the command line:
gccp is just the name of the shell file I wrote.... it could just as well be named domylaundry...
Since I have it added to the environment path variable, I don't have to use it's full path to call it.
still not working...
now it is:
g++ $1 $2 $3 -o program -pedantic-errors -Wall which should equate to what you wrote.
also, echo $1 $2 $3 yeilds "main.cpp common.cpp cursesclass.cpp", so it should work.
(the reason it's done like this is so I don't have to create a new one for every project I create, I can just run it from I command line that has the path in it's environment variable)
I have:
main.cpp
common.cpp
cursesclass.cpp (i wrapped up curses...)
I get an executable; same results: can't run it. It just acts like i pressed enter without any commands...
Does it run now, or does it still say Unable to run binary file?
In case it doesn't say it, what's in your main.cpp ?
Otherwise, you may want to download Code::Blocks to make sure your development set-up is good (I think installing Code::Blocks will also download the other [software] requirements, if there are any).
Unless you are using another compiler g++ is what you need, and it is default for many distros and IDEs. If you want to write a small program try making a script. I usually have a ./compile.sh
g++ -o myProgram.run *.cpp *.h
g++ -o myProgram.run *.cpp
This should compile all of the .cpp and .h files in the current directory. Than you can run your new application with ./myProgram.run
Of course this is a sloppy way of doing it, research make files, using g++ to build object files and linking them, or use an IDE like Code::Blocks. Seeing the build log of Codeblocks will give you an idea how g++ works.
I know how G++ works, it just another program to pass a bunch of arguments to...
Also, I figured out the problem and I fell like a HUGE MORON for over-seeing this:
main() called nothing and returned without calling my test function... DOY... And hence the root of what used to be my "troubles"...
Anyway, it's running now, and now I can't get curses to clear the infernal screen... The getch() function works lovely though! :) I might switch to it in windows, because I wrapped it in a class I wrote to handle the initialization and destruction of curses for me.
1 2
ccurses().cls()
ccurses().gkey()
nice huh?
cls() doesn't work though. it just acts as though it's never called...
1 2 3 4 5
void ccurses::cls()
{
erase();
refresh();
}
I think this is correct... I hope...
Also, I would apppreciate it if I could get some documentation. I tried searching myself, and couldn't find much. I need somthing that lists all of the functions/variables.
How do I compile a simple C program?
Start your favourite text editor and type in your source code. For example, I may use pico:
pico hello.c
and type in the Kerningham and Richie (the creators of "c") intro example of a C program:
./makefile: line 1: PROG: command not found
./makefile: line 2: SRC: command not found
./makefile: line 3: CXXFLAGS: command not found
./makefile: line 5: all:: command not found
./makefile: line 7: clean:: command not found
rm: missing operand
Try `rm --help' for more information.
./makefile: line 11: ${LINK.cc}: bad substitution