Winsock Program in c language is not working - c

I've started another program to run Winsock in C language on Windows7.
I found this help on msdn:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms737591%28v=vs.85%29.aspx
This program is not working and showing these errors:
$ gcc ak1.c -o ak1.exe -lwsock32 -lws2_32 -lAdvapi32 -lmswsock
C:\Users\rahul\AppData\Local\Temp\ccWqZC7C.o:ak1.c:(.text+0x109): undefined re
ference to `getaddrinfo'
C:\Users\rahul\AppData\Local\Temp\ccWqZC7C.o:ak1.c:(.text+0x1fa): undefined re
ference to `freeaddrinfo'
c:/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../../mingw32/bin/ld.exe: C:\Users\a
mit\AppData\Local\Temp\ccWqZC7C.o: bad reloc address 0x20 in section `.eh_frame'
c:/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../../mingw32/bin/ld.exe: final link
failed: Invalid operation
collect2.exe: error: ld returned 1 exit status
Is this error related to MICROSOFT SDK for Windows7, means these libraries are not added on my system.
I checked "Advapi32" is not under my micrsoft SDK.
Help please !!!

You're using GCC (presumably MinGW) which doesn't use Microsoft's SDK. getaddrinfo() and freeaddrinfo() are declared in MinGW's ws2tcpip.h implementation, but only if WinXP or later is targeted.
Add -D_WIN32_WINNT=0x0501 to your compiler command line to target XP.

the solution is to add "-lws2_32" at the end of the command to compile with gcc ;-)

Related

GCC - Compiling C undefined reference to `wWinMain'

I'm trying to compile C with gcc in command prompt but I'm getting this undefined reference to `wWinMain' error.
I was getting undefined reference to `WinMain' first but I fixed that by adding the argument:
-municode
Now `wWinMain' is undefined. How to fix this?
C:\Development\WA\Library\Backend\C\CB\CB>gcc CB.c -lssl -lcrypto -municode
C:/Strawberry/c/bin/../lib/gcc/x86_64-w64-mingw32/8.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
C:/Strawberry/c/bin/../lib/gcc/x86_64-w64-mingw32/8.3.0/../../../../x86_64-w64-mingw32/lib/../lib/libmingw32.a(lib64_libmingw32_a-crt0_w.o):crt0_w.c:(.text+0x21): undefined reference to `wWinMain'
collect2.exe: error: ld returned 1 exit status
gcc CB.c -lssl -lcrypto will compile and link an application, which on Windows defaults to a windowed application for which the entry point is WinMain (which your library obviously does not have nor need).
Adding the -municode just instructs the system to use the windows unicode API and then the entry point becomes wWinMain, and you still have the same problem.
To build a DLL, add -shared: gcc CB.c -shared -lssl -lcrypto
You didn't provide any of your code. And the problem I encountered is similar to this, so I'll describe the experience I had.
I was try out Dear ImGui library, and when I added the -municode option, the linker complained the same thing as yours. I did some searching, and found an answer to a similar question and another comment discussing a related problem, they both suggesting change "main" to "wmain". I did that, and the build was able to succeed.
I'm not knowledgeable enough to provide any deeper information about the source of the problem though.

Installing AODV protocol on Raspberry pi (https://github.com/erimatnor/aodv-uu)

I'm trying to install AODV protocol on Raspberry pi. After completing git clone from "https://github.com/erimatnor/aodv-uu" when I tried to do "make" and I am getting below error. Expecting your suggestion. Thank you!
make
gcc -Wall -O3 -g -DDEBUG -DCONFIG_GATEWAY -DDEBUG -o aodvd main.o list.o debug.o timer_queue.o aodv_socket.o aodv_hello.o aodv_neighbor.o aodv_timeout.o routing_table.o seek_list.o aodv_rreq.o aodv_rrep.o aodv_rerr.o nl.o locality.o
aodv_neighbor.o: In function neighbor_add':
/home/pi/aodv-uu/aodv_neighbor.c:68: undefined reference tohello_update_timeout'
aodv_timeout.o: In function route_discovery_timeout':
/home/pi/aodv-uu/aodv_timeout.c:98: undefined reference tort_table_update_timeout'
aodv_rreq.o: In function rreq_route_discovery':
/home/pi/aodv-uu/aodv_rreq.c:460: undefined reference tort_table_update_timeout'
aodv_rreq.o: In function rreq_local_repair':
/home/pi/aodv-uu/aodv_rreq.c:521: undefined reference tort_table_update_timeout'
aodv_rrep.o: In function rrep_forward':
/home/pi/aodv-uu/aodv_rrep.c:231: undefined reference tort_table_update_timeout'
nl.o: In function nl_kaodv_callback':
/home/pi/aodv-uu/nl.c:282: undefined reference tort_table_update_timeout'
collect2: error: ld returned 1 exit status
Makefile:112: recipe for target 'aodvd' failed
make: *** [aodvd] Error 1
The code available from sourceforge is the same code that is on github. If you download the archive, you'll see that the latest modification date of any file there is 2010. Given the age of this code, I wouldn't be surprised to find that things simply don't work anymore.
However, here's a quick workaround for your problem. The root cause appears to be that the problem functions, like rt_table_update_timeout, are declared as inline, but that information seems to get lost somewhere in the build process such that other object files are trying to reference these as non-inline functions.
You can avoid this by opening defs.h, looking for this line:
#define NS_INLINE inline
And replace it with:
#define NS_INLINE
This will allow aodvd to compile correctly (make aodvd). On my system, the kernel module will subsequently fail to compile:
cc1: fatal error: /lib/modules/4.13.15-100.fc25.x86_64/build/include/linux/modversions.h: No such file or directory
As far as I can tell, the modversions.h file is no longer produced by modern Linux kernels.

Issue with JACK on Raspian

After a successful configuration, build and installation of JACK v.2 from source, I am trying to compile a simple JACK client example:
pi#raspberrypi:~/jack $ gcc -o simple_client simple_client.c -l jack
However, the compiler returns the following errors:
/usr/bin/ld: /tmp/cc7341zz.o: undefined reference to symbol 'sin##GLIBC_2.4'
//lib/arm-linux-gnueabihf/libm.so.6: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
Are they probably due to the ARM processor architecture? Can you, please, suggest me some hint about how to solve them?
Source code of the simple_client.c file is available at this link. Furthermore, it has been successfully compiled and tested on macOS Sierra.

Undefined reference to symbol 'sem_post##GLIBC_2.4

I am trying to build a sample code using Eclipse and ARM Sourcery Windows GCC C on Windows 8 machine.
When I compile code :
I get this error :
Undefined reference to symbol 'sem_post##GLIBC_2.4
The error doesn't say any line number or any location about the error, so I don't know which part of the code I should post.
How can I get rid of this error?
Thanks.
sem_post() lives in the pthread library, so make sure you use the -pthread flag when compiling and linking.
gcc <filename.c> - o -lpthread -lrt
Specifying the -lpthread flag, when compiling solved the issue for me

MPG123 library: function mpg123_encsize not found

This is my very first experience with the MPG123 library, and I'm a bit confused.
I found a small example about using this library, with libao, but when i try to compile I got an error.
This is the example code "Play local files": http://hzqtc.github.io/2012/05/play-mp3-with-libmpg123-and-libao.html
I compile with: gcc -O2 -o play play.c -lmpg123 -lao
The error I get is:
/tmp/ccmEoxBp.o: In function `main':
play.c:(.text.startup+0x8d): undefined reference to `mpg123_encsize'
collect2: ld returned 1 exit status
What am I missing?
You have an old version of the mp123 library, according to the release notes it was added in 26.0.26
https://github.com/gypified/libmpg123/blob/master/NEWS.libmpg123
26.0.26
- Added mpg123_encsize().
- Added flag MPG123_SKIP_ID3V2.

Resources