|Dec 22, 2006, 10:43 PM||#1|
Opening Files Compiled By GCC
How do I open compiled C files? I compiled something with GCC in the terminal. Is it possible to open it? If not, how would I compile the same thing in XCode? Thanks!
P.S. I'm a nub at everything Mac.
|Jan 3, 2007, 05:43 PM||#3|
Let me try to lay some groumd work for you. Your computer only understands one thing...bits. This isn't a condecending statement, but its one that many people dont realize. To say it another way, your computer doesn't know jack about C, C++, Java, SmallTalk, Objective-C, Assembly, etc, etc...it only knows binary 1's and 0's.
So, what you see as a "Language" is actually a human representation of what we want the computer to do. Saying something like:
int a = 1 + b;
May look like "Add 1 + b and put it into a" to you, but to the computer its a
RED<address of b>,<register 1>
RED<value 1>,<register 2>
ADD<register 1>,<register 2>,<register 3>
STO<register 3>,<address of a>
and so on. And single line of C or C++ code could potentially create thousands and thousands of machine instructions that are moving address pointers, copying memory spots, allocating memory, etc.
There are basically three types of languages:
In any case, the end goal is to translate the Human-readable text into machine-readable instructions.
So, lets delve a little deaper into the original language of topic: C.
C is a completly compiled language. It is compiled in three steps. First, the original file is "parsed", that is it is ran through some language rules to determine if you followed the rules of the language and to process any macros and such. Then the resulting files are "Linked", that is inter-dependecies are satified (your includes), variables are stripped out (computers dont know what 'int a' is, it only knows memory addresses and registers), code optimizations occur, and finally the simple lines you typed are converted into many lines of Assembly code, . Assembly is basically machine code, but in human readable form. Finally, the Assembly code is then futher optimized and "assembled" into the final form, which is an executable binary that can be understood by the computer.
So, what started out as your file gets tossed and turned and churned several times over until it looks nothing like what you started with.
There is hope! First off, there are programs called "decompilers", which will take a binary file and convert it back to Assembly, and some even all the way back to the original language. Coverting to Assembly is one thing, as its just readably machine code, optimazations aside, but to convert to the original language, well, that takes some "guess work".
First problem is that all the variables names have been stripped. So, an 'int a' is no longer 'a', but some offset to a memory address. This is also the case for method names as well. Second, there are several levels of "optimazations" done, which basically swap poor code thats highly readable with faster code that highly cryptic. On top of that, things like for loops and if statements just dont exist to the computer, and end up being converted to memory jumps and compares. So, the decompiler has to "interpret" the machine code to look for patterns that could possibly be an if statement or a for.
What you end up with is something that is sorta readable, but no where near what it started out with.
I hope this helps you some. Or, in the least I hope it didn't put you to sleep .
|Jan 3, 2007, 05:59 PM||#4|
mbabauer, Wow, nice-mini essay very informative, just need to figure out exactly how it is relates to the question. I presume that it would be helpful if he wanted the code from the actual program, but it seems that he has the code because he asked if he should use Xcode.
P.S. AFAIK Xcode uses gcc for compiling projects. just uses makefiles and stuff
MB, 2.0Ghz, 2GB Ram, 80GB
|Jan 3, 2007, 07:57 PM||#5|
|Thread Tools||Search this Thread|
|thread||Thread Starter||Forum||Replies||Last Post|
|GCC compiled program not working||zt0ne||Mac Programming||24||Feb 5, 2014 02:28 PM|
|Opening .lnk files???||davidra||Windows, Linux & Others on the Mac||0||Aug 27, 2013 07:12 AM|
|Preview keeps opening old files||walknice||OS X||5||Jul 17, 2013 03:35 AM|
|Searching for text within pdf files -- without opening the files?||Fishrrman||Mac Applications and Mac App Store||7||Jul 3, 2013 02:20 PM|
|Opening Files||Stumpy25||OS X 10.8 Mountain Lion||2||Apr 24, 2013 12:32 PM|
All times are GMT -5. The time now is 08:31 PM.