473,405 Members | 2,310 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

making a simple module

I have the made the 3 following files:

1) my headerfile "draft.h":

struct tkb {
int *prio;

};
int init();
int test();

2) file with the implementation of the functions called "draft.c":
#include<stdio.h>
#include<stdlib.h>
#include "draft.h"

static struct tkb first_thread;
struct tkb *current = &first_thread;

int init()
{
int a = 222;
current->prio = &a;
printf("init :%d\n", *current->prio);
return 0;
}

int test()
{
printf("test : %d\n",*current->prio);

return 0;
}
3) And a file containing a main function that can use the functions called
"start.c":
#include "draft.h"
#include<stdio.h>
#include<stdlib.h>

int main()
{

init();

return 0;

}

but how do I compile the three files into a working program?

Johs

Mar 14 '06 #1
5 1888
On 2006-03-14, Johs32 <df***@dsf.com> wrote:
I have the made the 3 following files:

1) my headerfile "draft.h":

struct tkb {
int *prio;

};
int init();
int test();

2) file with the implementation of the functions called "draft.c":
#include<stdio.h>
#include<stdlib.h>
#include "draft.h"

static struct tkb first_thread;
struct tkb *current = &first_thread;

int init()
{
int a = 222;
current->prio = &a;
printf("init :%d\n", *current->prio);
return 0;
}

int test()
{
printf("test : %d\n",*current->prio);

return 0;
}
3) And a file containing a main function that can use the functions called
"start.c":
#include "draft.h"
#include<stdio.h>
#include<stdlib.h>

int main()
{

init();

return 0;

}

but how do I compile the three files into a working program?


Depends what your "development environment" is.

If it's Linux, or something similar, you can just go

$ gcc start.c draft.c

and your program will appear as a file called a.out. But better to have
a look at make and learn how to do makefiles.

On some other systems with a graphical IDE you might have to create what
they usually call a "Project" using the menus.
Mar 14 '06 #2
Ben C wrote:
On 2006-03-14, Johs32 <df***@dsf.com> wrote:
I have the made the 3 following files:

1) my headerfile "draft.h":

struct tkb {
int *prio;

};
int init();
int test();

2) file with the implementation of the functions called "draft.c":
#include<stdio.h>
#include<stdlib.h>
#include "draft.h"

static struct tkb first_thread;
struct tkb *current = &first_thread;

int init()
{
int a = 222;
current->prio = &a;
printf("init :%d\n", *current->prio);
return 0;
}

int test()
{
printf("test : %d\n",*current->prio);

return 0;
}
3) And a file containing a main function that can use the functions
called "start.c":
#include "draft.h"
#include<stdio.h>
#include<stdlib.h>

int main()
{

init();

return 0;

}

but how do I compile the three files into a working program?


Depends what your "development environment" is.

If it's Linux, or something similar, you can just go

$ gcc start.c draft.c

and your program will appear as a file called a.out. But better to have
a look at make and learn how to do makefiles.

On some other systems with a graphical IDE you might have to create what
they usually call a "Project" using the menus.

Ok I have now made the following makefile:

CC=gcc
CFLAGS=-g

all:draft
draft: draft.o start.o
$(CC) $(CFLAGS) draft.o start.o -o run

draft.o: draft.c draft.h
$(CC) $(CFLAGS) -c draft.c

start.o: start.c draft.h
$(CC) $(CFLAGS) -c start.c

clean:

it seems to work fine. Is there something I am missing?

Mar 14 '06 #3
Johs32 <df***@dsf.com> writes:
I have the made the 3 following files:

1) my headerfile "draft.h": [snip] 2) file with the implementation of the functions called "draft.c": [snip] 3) And a file containing a main function that can use the functions called
"start.c": [snip] but how do I compile the three files into a working program?


I'd use a compiler.

You're asking about how to use your tool set, not about the C
programming language. The answer depends on which compiler and
operating system you're using. The answer should also be reasonably
easy to find in your system's documentation.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Mar 14 '06 #4
On 2006-03-14, Johs32 <df***@dsf.com> wrote:
Ok I have now made the following makefile:

CC=gcc
CFLAGS=-g all:draft
You ought to put

..PHONY: all

It's just that if you have an actual file called "all" things can get
very confusing.
draft: draft.o start.o
$(CC) $(CFLAGS) draft.o start.o -o run
You don't want CFLAGS there, but possibly LDFLAGS (if you need any
linker flags).
draft.o: draft.c draft.h
$(CC) $(CFLAGS) -c draft.c

start.o: start.c draft.h
$(CC) $(CFLAGS) -c start.c
You can make gcc generate the dependencies on header files for you, see
under gcc -MM. But this is all right.
clean:
After clean you'd want something like "rm *.o run". And you'd want to
make clean PHONY as well.
it seems to work fine. Is there something I am missing?


I don't think my first makefile was half as good as this one!
Mar 14 '06 #5
Johs32 <df***@dsf.com> writes:
Ben C wrote:
On 2006-03-14, Johs32 <df***@dsf.com> wrote:
I have the made the 3 following files: [snip] but how do I compile the three files into a working program?
Depends what your "development environment" is.

[snip] Ok I have now made the following makefile:

CC=gcc
CFLAGS=-g [snip] it seems to work fine. Is there something I am missing?


Yes, you're missing the fact that you're not asking a C language
question. For system-specific issues like tihs, try
comp.unix.programmer (or some other newsgroup appropriate to your
system).

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Mar 14 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Andrew Henshaw | last post by:
Yesterday, I was writing some test code for a module and I wanted some line-oriented text to use as a data source. I thought about using a docstring from one of the standard modules; but, it...
1
by: Kenneth McDonald | last post by:
I'm working on the 0.8 release of my 'rex' module, and would appreciate feedback, suggestions, and criticism as I work towards finalizing the API and feature sets. rex is a module intended to make...
3
by: Ryno Rijnsburger | last post by:
I am busy packaging our product as a standard Setup project in VS.NET that uses a bunch of merge modules (basically, a merge module for every key infrastructure component in our system). Part...
2
by: Lumpierbritches | last post by:
I have code I'm using repeatedly in my program, and would like to convert it to a module or macro, can anyone assist me? Thank you in adavance for all assistance, it is greatly appreciated. Dim...
8
by: Phil D | last post by:
Hi, I am new to c# and oop and have a question about interfaces which I hope someone can help me with. The book I am using (C# Step by Step) explains how to create and implement interfaces...
1
by: Shawn B. | last post by:
Greetings, I have have been working for almost 18 months on a set of WebControls where some are similar to the ASP.NET standard and well-enhanced while other controls are completely new and...
90
by: Ben Finney | last post by:
Howdy all, How can a (user-defined) class ensure that its instances are immutable, like an int or a tuple, without inheriting from those types? What caveats should be observed in making...
11
by: Rikishi 42 | last post by:
Hi, I'm new to this group. I've tried finding my answer in existing messages, but no such luck. What I want to do is to compile/bundle/prepare/whatever_term a simple Python script for...
2
by: kj | last post by:
I'm sure this is a simple, but recurrent, problem for which I can't hit on a totally satisfactory solution. As an example, suppose that I want write a module X that performs some database...
3
by: Phillip B Oldham | last post by:
In my attempt to learn python in a weekend, I've fallen foul at line 10 of my second scripting attempt. Basically I'm writing a simple spider, but currently I'm unable to find any documentation on...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.