Ceelos
Ceelos

Reputation: 1126

About linking files using Mac terminal

Okay here goes, I'm completely new at this, started learning the terminal just about 2 days ago. I'm slowly but surely getting the hang of it, now I'm stuck on this and I've been trying to fix it for a good hour. It's a rather simple question as I am a newby.

I have a C file in my desktop and a Header file in a folder in my desktop. I'm including that header in my C file. I have to link them (currently doing a tutorial, it tells me to link, but doesn't show me how).

Upvotes: 0

Views: 719

Answers (2)

Mark Setchell
Mark Setchell

Reputation: 207670

You have a couple of options. First, you will need to install the software development environment - it's called Xcode. I think you can get it for free on the AppStore, if not Google it.

Then you need to decide if you want to develop and compile graphically in the Xcode Integrated Development Environment. If you do, start Xcode and create a new project and open your C file and change the "include path" to match the location of your header file. Then click "Build" and "Run"

If you want to do things at the commandline, you'll need to install "Xcode Command Line Tools" - Google it. That will give you a compiler. Then you can compile. I'm not certain which compiler you will get - it could be "llvm" or "gcc" or something else, but the command you are looking for will be something like:

gcc -o prog -I /path/to/HeaderFileFolder yoursourcecode.c

which will give you a program called "prog" that you can run by typing

./prog

Upvotes: 1

Dave Louw
Dave Louw

Reputation: 13

You are likely confusing two different concepts. The "link" mentioned in the tutorial is probably talking about turning the compiled objects into a single executable. See http://www.cprogramming.com/compilingandlinking.html for an explanation of what linking means in this context.

What you've provided examples of doing is file system linking, which is totally unrelated.

Providing more details on the tutorial could help refine this answer.

Upvotes: 1

Related Questions