Page 1 of 1

Linker problems calling function getcwd() on unistd.h header

Posted: Mon Jul 07, 2014 4:33 am
by geolab
Hello everybody,

I am not able to compile a simple project with only a main function with a call to the function:

getcwd();

Doing a CTRL+Click on the function call (and adding the typical include line on the top of the code) brings me to the expected header, but when compiled, an error appear (I think is a linker problem).

This is the code:

#include "predef.h"

#include <ucos.h>
#include <ip.h>
#include <stdio.h>
//#include <sys/unistd.h>
#include <unistd.h>
#include <buffers.h>

extern "C" {
void UserMain(void * pd);
}

void UserMain(void * pd) {
InitializeStack();
OSChangePrio(MAIN_PRIO);

iprintf("Application started\n");

char buf[2];
int s = 1;

getcwd ( buf, s); //There is the error
}

The compiler directories are OK (project settings), but I am not sure of have added the correct linker libraries. By now, I've added the libraries:

MOD5441X.a
NetBurner.a
FatFile.a
debugLibrary.a
Lua_Full

Which could be the librarie that link to <unistd.h>? (or to <sys/unistd.h>)

The error in NBEclipse is: "undefined reference to `getcwd'". Any help or comment will be very appreciated.

Regards,
Enric

Re: Linker problems calling function getcwd() on unistd.h he

Posted: Mon Jul 07, 2014 11:08 am
by dciliske
Umm... I'm not sure getcwd makes sense to even use in an embedded environment. Can you articulate what you are attempting to do?

Also, when I say that I'm not sure it even makes sense, that's because you're effectively running the program you're writing as the OS, not something launched from a shell.

-Dan

Re: Linker problems calling function getcwd() on unistd.h he

Posted: Mon Jul 07, 2014 11:22 am
by sulliwk06
If you're using the EFFS FAT file system, I believe there is an f_getcwd. Otherwise I'm not sure what you expect getcwd to return.

Re: Linker problems calling function getcwd() on unistd.h he

Posted: Fri Jul 11, 2014 12:05 am
by geolab
Thanks to dciliske and sulliwk06. Now, I don't use anymore the getcwd() function.