I am running a simple C program having fork() call with cygwin environment using gcc compiler. It compiles well but while writing gcc Filename.c it shows error as:
$ gcc A.c
C:\cygwin\tmp\ccEkivvm.o:A.c:(.text+0x24): undefined reference to `fork'
collect2: ld returned 1 exit status
Can't we use fork() with cygwin on windows?
Did you forget to include the header
#include <unistd.h>
?
To the best of my knowledge, that would define fork() when using Cygwin.
Also, take a look at this question, you might be having the same problem:
Problem compiling program using fork in cygwin
Related
I'm trying to build GNUjump on Arch Linux (release 1 Oct. 2014), but i'm getting a strange error, and i don't know what to do.
./configure shows me no error. So, i launch make, and this appears:
/usr/bin/ld: SDL_rotozoom.o: undefined reference to symbol 'sincos##GLIBC_2.1'
/usr/lib/libm.so.6: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
The same Makefile, on a Debian-based PC, works.
Surely, i'm missing something, but i don't know what.
You need to include -lm in the compiler/linker command line to link against the standard math library math.h.
See this: Why do you have to link the math library in C?
i am trying to build a custom version of the linux kernel 3.8 and i want my linker to behave a bit different so i changed its ldscripts.
Specifically I configure binutils -> make -> change ldscripts -> make install.
However when i try to compile libc using my linker the only thing i see is this :
GNU ld (GNU Binutils) 2.23
Supported emulations:
elf32_sparc
sparclinux
elf64_sparc
sun4
using internal linker script:
==================================================
/* Script for --shared -z combreloc: shared library, combine & sort relocs */
etc
The thing is that i have changed my ldscripts and prepended a tag at the beginning of each script in order to recognize them but my compiler does not seem to care.
However i don't have any other elf scripts in my system so the option of searching the wrong library path is not actually an option.
Is there something i am missing here?
Notice that i am cross compiling for sparc
You can pass a custom linker script to ld:
ld -T <path/to/file> ...
or to gcc:
gcc -Wl,-T,<path/tofile> ...
Default ld scripts get compiled into compiler driver (gcc) so you should at least rebuild the toolchain.
That's also probably the case that gcc will not look at any linker scripts other than built into it, so you'll have to modify them in toolchain (it's probably in spec files somewhere).
I am running client.c code in linux pangolin 12.04, happycoders-libsocket is installed
but still got error that says:
/usr/bin/ld: cannot find -lsocket
collect2: ld returned 1 exit status
May I know what can be done to resolve this please?
If you have C code that uses BSD sockets on Linux then you do not need to link against additional libraries; GLibC provides the socket functions through libc.
I wrote a basic hello world program in haskel and tried to compile it with:
ghc filename.hs. It produces .hi and .o files but no executable and displays
this error in the linker:
marox#IT-marox:~/Marox$ ghc tupel.hs
Linking tupel ...
/usr/bin/ld: --hash-size=31: unknown option
/usr/bin/ld: use the --help option for usage information
collect2: ld returned 1 exit status
Googling didn't return any useful information.
I am on ubuntu 12.04.
How can I fix this?
Have you binutils-gold installed? If yes, this is the problem (since the gold linker does not support --hash-size AFAIK).
Possible solutions:
remove gold
your ld probably links to ld.gold, so change the symlink to ld.ld
tell the haskell compiler explicitly which linker to use with the -pgml option: ghc -pgml ld.ld tupel.hs
install ghc from source, since the configure script of ghc will then build ghc so that it won't use --hash-size
Depending on your version of ghc, you can adjust the linker settings in ghc's setting file /usr/lib/ghc-your.ghc.version/settings
Update - gold on Ubuntu 12.10 appears to move GNU ld to ld.bfd. To fix this problem I deleted the ld link as recommended and remade the link with
ln -s ld.bfd ld
ghc compilations are now going through.
(Couldn't see how to subvert the settings file in usr/lib/ghc, as the entry is for gcc which passes through its commandline to ld, although this would have been my preferred option, in case something else needs ld to be the way it was.)
Thanks to Dominic for the pointer of where to look! It was driving me crazy...
I'm trying to compile a very old verion of slapd (the LDAP server) on cygwin. Previously this ran on a Linux box, but for reasons beyond my control it must be made to work on a Windows server. It has been suggested that we might use cygwin to compile up the source-code.
Unfortunately the build fails during "configure" with the error message:
checking how to run the C preprocessor... cc -E
checking for gcc... (cached) cc
checking whether the C compiler (cc ) works... no
configure: error: installation or configuration problem: C compiler cannot creat
e executables.
The last few lines of config.log are:
configure: failed program was:
#line 2822 "configure"
#include "confdefs.h"
int main() {
return __EMX__;
; return 0; }
configure:2845: checking how to run the C preprocessor
configure:2866: cc -E conftest.c >/dev/null 2>conftest.out
configure:2950: checking for gcc
configure:3063: checking whether the C compiler (cc ) works
configure:3079: cc -o conftest conftest.c 1>&5
/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../../i686-pc-cygwin/bin/ld: cannot find
-luser32
collect2: ld returned 1 exit status
configure: failed program was:
#line 3074 "configure"
#include "confdefs.h"
main(){return(0);}
UPDATE: This is a win32 computer - cygwin does not included a shared-object called user32, but Windows XP does include an object called user32.dll - any idea if this might be what the linker is looking for?
UPDATE2: w32api is already installed, (3.13-1) - I note that there is a user32.lib as part of visual-stuido 2003 .Net - is there a way to make GCC in Cygwin use this?
The root cause seems to be
/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../../i686-pc-cygwin/bin/ld: cannot find -luser32
This is either a problem with your cygwin installation, or the configure scripts are to old to recognise and handle the installation.
If -luser32 is failing, try installing the w32api Cygwin package.
After much trial & error I found the correct answer for this problem: The reason for this error is that the Cygwin environment was not set up correctly.
The login-user on a domain, and so the /etc/passwd & /etc/group files were not set up correctly by default. The solution was to make a local user-account and then re-build the passwd and groups files.
After that, GCC could build just fine.
Sounds crazy, I know.