how to use getcwd.h? (Development MSX Fora)MSX Resource Center            
            
English Nederlands Espa�ol Portugu�s Russian         
 Nieuws
   Voorpagina
  Nieuws archief
  Nieuws onderwerpen

 Informatie
   MSX Fora
  Artikelen
  Recensies
  Beursverslagen
  Fotoreportages
  Beurzen en meetings
  Enquêtes
  Links
  Zoek

 Software
   Downloads
  Webshop

 MRC
   Wie we zijn
  Kom bij ons team
  Doneren
  Policies
  Contact met het MRC
  Link naar Ons
  Statistieken

 Zoek
 
  

  

 Login
 

Gebruikersnaam

Wachtwoord




Ben je nog niet lid? Klik hier en word MSX vriend!


 Statistieken
 

Er zijn 54 gasten en 5 MSX vrienden online

Je bent een anonieme bezoeker.
 

MSX Fora


MSX Fora

Development - how to use getcwd.h?

Schrijver

how to use getcwd.h?

diederick76
msx user
Berichten: 63
Geplaatst: 12 April 2006, 17:56   
Hi,

A long time ago I think I used to know stuff like this, but right now I'm completely in the dark. I downloaded the hitech-c PMA files form funet and the modified compiler from MSX Banzai, and now I want to use the getcwd.c file I found in one of these PMA files. To test them, I'm trying to compile the tstcwd.c file that came with it. It starts with

#include <stdio.h>
#include <sys.h>    /* defines getcwd */
...


The manual I found in one of the other PMA file agrees that sys.h contains getcwd. sys.h is in place, and getcwd.c too. There is no file called sys.c. Now what must I do to make

# cc tstcwd.c

return something else than:

undefined symbol:
_getcwd


manuel
online
msx guru
Berichten: 3530
Geplaatst: 12 April 2006, 19:00   
You should link with the library (.lib file?) that contains the getcwd symbol.
Header files are only for the preprocessor.

Follow any basic C course!
diederick76
msx user
Berichten: 63
Geplaatst: 12 April 2006, 19:26   
Quote:

You should link with the library (.lib file?) that contains the getcwd symbol.
Header files are only for the preprocessor.



I couldn't find in the manual how to do exactly that, but it appears that

# cc tstcwd.c getcwd.c

did the trick. I got a tstcwd.com out of it as well as object files of both of them. Would this be the proper way? I don't see the point of header files then Indeed, when I compile another program which uses the getcwd function but doesn't have the
#include <sys.h>
preprosessor directive using:

# cc myprog.c getcwd.o

everything goes fine.

Quote:

Follow any basic C course!



I did, years ago. I remember what a pointer is for example, but things like header files appear easy to forget for me.
arnold_m
msx lover
Berichten: 85
Geplaatst: 12 April 2006, 22:39   
Quote:

Quote:

You should link with the library (.lib file?) that contains the getcwd symbol.
Header files are only for the preprocessor.



I couldn't find in the manual how to do exactly that, but it appears that

# cc tstcwd.c getcwd.c

did the trick. I got a tstcwd.com out of it as well as object files of both of them. Would this be the proper way?


This works indeed, but this way you'll have to mention all the source (or object) files you need by hand. The proper way to do it is
cc tstcwd.c -ldos2

The "-ldos2" option is mentioned in libdos2.txt.
Hey! The getcwd function in libdos2 is written in assembly, so you are using a different set of alternative library functions. You may want to consider using libdos2 and libfix instead.

Quote:

I don't see the point of header files then [...]


The point of header files is to tell the compiler that there is a function called getcwd that takes an integer argument and returns a char pointer. The compiler can then issue a warnings or error messages if you try something like:
int i;
i = getcwd("A:");

AuroraMSX

msx master
Berichten: 1260
Geplaatst: 14 April 2006, 15:00   
Quote:

Quote:

I don't see the point of header files then [...]


The point of header files is to tell the compiler that there is a function called getcwd that takes an integer argument and returns a char pointer. The compiler can then issue a warnings or error messages if you try something like:
int i;
i = getcwd("A:");


<Alert mode="nitpickers">
Actually, "to tell the compiler that there is a function with a certain name, set of arguments and return type" is the point of a declaration, and header files are usually used as "declaration containers". Instead of #include-ing a bunch of header files you can also declare each function an type and global variable you use manually in your source code...
/* bla.c */
extern int printf(char *format, ...);

int main() {
    printf("wokka wokka");
}

works just as well as
/* bla2.c */
#include <stdio.h>

int main() {
    printf("boogabooga");
}


(provided I've got the signature of printf() right )
</Alert>
 
 







(c) 1994 - 2008 Stichting MSX Resource Center. MSX is een trademark van MSX Licensing Corporation.