473,671 Members | 2,327 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Linker error in compilation

Hi,
I wrote a small socket program in C++ using unix machine.
Compiler CC.
It is asking some library file or linker file
Could you please send the library files or linker files for following
program.

error:
$ CC server_socket.c pp -lsocket -lm -lc -lrt
Undefined first referenced
symbol in file
int unlink(const char*) server_socket.o
int close(int) server_socket.o
---------------------------------------------------------------------------*-----
$CC client_socket.c pp -lsocket -lm -lc -lrt
Undefined first referenced
symbol in file
int close(int) client_socket.o
---------------------------------------------------------------------------*------
Program:
-----------------
server: server_socket.c pp
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#define SOCK_PATH "echo_socke t"
int main(void)
{
int s, s2, t, len;
struct sockaddr_un local, remote;
char str[100];
int unlink(const char *path);
int close(int);
if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
perror("socket" );
exit(1);
}
local.sun_famil y = AF_UNIX;
strcpy(local.su n_path, SOCK_PATH);
unlink(local.su n_path);
len = strlen(local.su n_path) + sizeof(local.su n_family);
if (bind(s, (struct sockaddr *)&local, len) == -1) {
perror("bind");
exit(1);
}
if (listen(s, 5) == -1) {
perror("listen" );
exit(1);
}
for(;;) {
int done, n;
printf("Waiting for a connection...\n ");
t = sizeof(remote);
if ((s2 = accept(s, (struct sockaddr *)&remote, &t)) ==
-1) {
perror("accept" );
exit(1);
}
printf("Connect ed.\n");
done = 0;
do {
n = recv(s2, str, 100, 0);
if (n <= 0) {
if (n < 0) perror("recv");
done = 1;
}
if (!done)
if (send(s2, str, n, 0) < 0) {
perror("send");
done = 1;
}
} while (!done);
close(s2);
}
return 0;
}
---------------------------------------------------------------------------*------------------------------------------------
client: client_socket.c pp
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#define SOCK_PATH "echo_socke t"
int main(void)
{
int s, t, len;
struct sockaddr_un remote;
char str[100];
int close(int a);
if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
perror("socket" );
exit(1);
}
printf("Trying to connect...\n");
remote.sun_fami ly = AF_UNIX;
strcpy(remote.s un_path, SOCK_PATH);
len = strlen(remote.s un_path) + sizeof(remote.s un_family);
if (connect(s, (struct sockaddr *)&remote, len) == -1) {
perror("connect ");
exit(1);
}
printf("Connect ed.\n");
while(printf("" ), fgets(str, 100, stdin), !feof(stdin)) {
if (send(s, str, strlen(str), 0) == -1) {
perror("send");
exit(1);
}
if ((t=recv(s, str, 100, 0)) 0) {
str[t] = '\0';
printf("echo%s" , str);
} else {
if (t < 0) perror("recv");
else printf("Server closed connection\n");
exit(1);
}
}
close(s);
return 0;
}
---------------------------------------------------------------------------*----
Please send me the linker file for close() and unlink()

Jul 6 '07 #1
4 2409
sr*********@gma il.com wrote:
Hi,
I wrote a small socket program in C++ using unix machine.
Compiler CC.
It is asking some library file or linker file
Could you please send the library files or linker files for following
program.

error:
$ CC server_socket.c pp -lsocket -lm -lc -lrt
Undefined first referenced
symbol in file
int unlink(const char*) server_socket.o
int close(int) server_socket.o
---------------------------------------------------------------------------*-----
$CC client_socket.c pp -lsocket -lm -lc -lrt
Undefined first referenced
symbol in file
int close(int) client_socket.o
---------------------------------------------------------------------------*------
Program:
-----------------
server: server_socket.c pp
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#define SOCK_PATH "echo_socke t"
int main(void)
{
int s, s2, t, len;
struct sockaddr_un local, remote;
char str[100];
int unlink(const char *path);
int close(int);

You should never do this. Your prototype is probably wrong for the
implementation you are using. Always use the correct header files
for getting the prototypes of system functions.

Eliminate this prototypes and recompile.

jacob
Jul 6 '07 #2
On Jul 6, 2:24 pm, srini4va...@gma il.com wrote:
Hi,
I wrote a small socket program in C++ using unix
machine.
Compiler CC.
CC ? C++ ?
It is asking some library file or linker file
Could you please send the library files or linker files for following
program.

error:

$ CC server_socket.c pp -lsocket -lm -lc -lrt

Undefined first referenced
symbol in file
int unlink(const char*) server_socket.o
int close(int) server_socket.o

---------------------------------------------------------------------------**-----

$CC client_socket.c pp -lsocket -lm -lc -lrt
Undefined first referenced
symbol in file
int close(int) client_socket.o

---------------------------------------------------------------------------**------

Program:
-----------------
server: server_socket.c pp
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>

#define SOCK_PATH "echo_socke t"

int main(void)
{
int s, s2, t, len;
struct sockaddr_un local, remote;
char str[100];
int unlink(const char *path);
int close(int);

if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
perror("socket" );
exit(1);
}

local.sun_famil y = AF_UNIX;
strcpy(local.su n_path, SOCK_PATH);
unlink(local.su n_path);
len = strlen(local.su n_path) + sizeof(local.su n_family);
if (bind(s, (struct sockaddr *)&local, len) == -1) {
perror("bind");
exit(1);
}

if (listen(s, 5) == -1) {
perror("listen" );
exit(1);
}

for(;;) {
int done, n;
printf("Waiting for a connection...\n ");
t = sizeof(remote);
if ((s2 = accept(s, (struct sockaddr *)&remote, &t)) ==
-1) {
perror("accept" );
exit(1);
}

printf("Connect ed.\n");

done = 0;
do {
n = recv(s2, str, 100, 0);
if (n <= 0) {
if (n < 0) perror("recv");
done = 1;
}

if (!done)
if (send(s2, str, n, 0) < 0) {
perror("send");
done = 1;
}
} while (!done);

close(s2);
}

return 0;
}
---------------------------------------------------------------------------**------------------------------------------------
client: client_socket.c pp

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>

#define SOCK_PATH "echo_socke t"

int main(void)
{
int s, t, len;
struct sockaddr_un remote;
char str[100];
int close(int a);

if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
perror("socket" );
exit(1);
}

printf("Trying to connect...\n");

remote.sun_fami ly = AF_UNIX;
strcpy(remote.s un_path, SOCK_PATH);
len = strlen(remote.s un_path) + sizeof(remote.s un_family);
if (connect(s, (struct sockaddr *)&remote, len) == -1) {
perror("connect ");
exit(1);
}

printf("Connect ed.\n");

while(printf("" ), fgets(str, 100, stdin), !feof(stdin)) {
if (send(s, str, strlen(str), 0) == -1) {
perror("send");
exit(1);
}

if ((t=recv(s, str, 100, 0)) 0) {
str[t] = '\0';
printf("echo%s" , str);
} else {
if (t < 0) perror("recv");
else printf("Server closed connection\n");
exit(1);
}
}

close(s);

return 0;
}

---------------------------------------------------------------------------**----

Please send me the linker file for close() and unlink()
for which OS ? on my solaris 5.8,linux, compilation using gcc works
without any Warning/Error. < i didn't look what your program is
doing , just try to compile the same>

Is any thing related to C ?
-Raxit

Jul 6 '07 #3
sr*********@gma il.com wrote:
Hi,
I wrote a small socket program in C++ using unix machine.
If this were a C++ problem (it isn't), you should ask in a C++
newsgroup. C++ is not C.
Compiler CC.
It is asking some library file or linker file
It is possible that you are missing a library, but unlikely. Your code
is missing a needed but non-standard (in C _and_ C++) header.
Could you please send the library files or linker files for following
program.
No. This newsgroup is not the vendor of your implementation, not is it
a sources.wanted newsgroup.
error:
$ CC server_socket.c pp -lsocket -lm -lc -lrt
Undefined first referenced
symbol in file
int unlink(const char*) server_socket.o
int close(int) server_socket.o
---------------------------------------------------------------------------Â*-----
$CC client_socket.c pp -lsocket -lm -lc -lrt
Undefined first referenced
symbol in file
int close(int) client_socket.o
The functions unlink() and close() are not standard C functions. They
are POSIX functions, for which a UNIX newsgroup might be appropriate but
not a C (or C++) newsgroup. In UNIX environments these functions are
declared in <unistd.h>, not a standard C header. Neither your
socket.cpp nor your client_socket.c pp programs include this header.

Your failure to #include <unistd.h>, your imagining that the resulting
is something that can be fixed with a "library file or linker file",
your thinking that a C newsgroup is an appropriate place to ask, as well
as several features of your code which are at best non-portable and
unidiomatic, all suggest that you are not ready to do what you are
trying to do. Attempting to do this level of programming when you have
not learned the basics of C or of the UNIX libraries is foolish. The
potential for harm is great.
Jul 6 '07 #4
Sheth Raxit wrote:
On Jul 6, 2:24 pm, srini4va...@gma il.com wrote:
Hi,
I wrote a small socket program in C++ using unix
machine.
Is any thing related to C ?

Please don't quote an entire large post just for a short reply like
that.


Brian
Jul 6 '07 #5

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

Similar topics

12
801
by: Baloff | last post by:
Hello I have this linker error which makes me think that the definition file is not being seen by the linker, this code is taken from "Thinking in C++, 2nd Edition, Volume 1, Annotated Solutions Guide" Using Dev-C++ 4.9.9.2, The error is: undefined reference to ‘f(int)’ all the following files are in the same dir. thanks
9
1771
by: Steven | last post by:
I am compiling with GCC 3.2, and it works well enough. However, sometimes when I try to link libraries, the linker throws "NOTAD.o(.eh_frame+0x11):NOTAD.C: undefined reference to `__gxx_personality_v0'". This never happened until about 3 days ago. What is __gxx_personality_v0? The linker works for many libraries, such as stdlib.h, strings.h, etc. However, sometimes it fails. In this particular case, "signals.h" is causing the...
0
995
by: Pavel | last post by:
Hi, I have c++ class library in which I use fopen/fclose from <stdio.h>. Compilation is OK, but the linker returns the following error: lib_jpeg error LNK2001: unresolved external symbol "struct _iobuf * __cdecl fopen(char const *,char const *)" (?fopen@@$$J0YAPAU_iobuf@@PBD0@Z) lib_jpeg error LNK2001: unresolved external symbol "int __cdecl fclose(struct _iobuf *)" (?fclose@@$$J0YAHPAU_iobuf@@@Z) I'm using external library which uses the...
0
2223
by: Tom McDermott | last post by:
I am having linker errors : error LNK2022: metadata operation failed (80131188) : Inconsistent field declarations in duplicated types This code linked sucessfully in C++.NET 2002, but does not link (causes several of these metadata errors) in C++.NET 2003.
6
1719
by: Igor Kravtchenko | last post by:
Hi, I'm having a pretty idiot problem under VC++ .NET but cannot solve it. I have an .exe A and a dll B. A uses some methods of B (so A depends of B). B exports its methods using __declspec(dllexport) and A imports them using __declspec(dllimport).
1
3284
by: developer | last post by:
Hi All I have made a .NET project. the files included are borland c++ files that i am migrate to VC++ .NET I am using Microsoft Visual C++ .NET 2003. the compilation goes through properly, but throws a load of linker errors
0
3468
by: Ehsan68 | last post by:
Hello my problem is "Linker Error: Undefined symbol _cga_driver_far in module maze.c " then Go to Options =>Linker =>Libraries This will display a box showing Container Class Turbo Version
1
4159
by: Deepath G | last post by:
This is deepath.. I am getting some linker error when i am trying to connect Websphere MQ using Borland C++ Builder 2006 using imqi.hpp on windows. Error Message ----------------------- Error: Unresolved external 'ImqMgr::~ImqMgr()' referenced from C:\DOCUMENTS AND SETTINGS\228753\MY DOCUMENTS\BORLAND STUDIO PROJECTS\DLLEXERCISE\DEBUG_BUILD\MANI.OBJ Error: Unresolved external 'ImqObj::~ImqObj()' referenced from C:\DOCUMENTS AND...
2
2421
by: Markus Dehmann | last post by:
What to do if an external library is header-files-only (but you have to use it), and you get lots of linker errors? You will necessarily get linker errors "multiple definition of ..." if you try to separate interface from implementation in your own code. The external-library symbols will first be defined in one .o file and then again in the next one that includes the same implementation-heavy header. Is there any way to avoid the...
0
8400
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8924
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8823
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8602
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7441
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6234
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4227
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2817
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1814
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.