473,216 Members | 1,398 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,216 software developers and data experts.

Wrong linkage of system functions

I'm having some trouble with a C project in a Linux system.
I already know which is the problem but I don't know how to fix it.

I have a program that links to a third party static library.
The problem is that the library declares a internal global variable
named 'accept' not visible by the user.
In my program I use the system Internet Sockets which API have a
function named 'accept'.
When I compile it does not complies but when I run the program it
segfaults because a call to Internet Sockets 'accept' function tries
to execute a function which address is the address of the 'accept'
global variable from the third party library.

I made a little source code that reproduce the problem with the
'printf' function. In this case the compiler gives me a warning, but
the beavior is equal.

Is this my problem? Is it a bug? I don't think a programer have to
know all possible system functions names...
I have three files:
mylib.c and mylib.h represents the third party library;
main.c is my program.
I also made a simple Makefile.

Here are the files:

$ cat mylib.h
int myfunc();

$ cat mylib.c
#include "mylib.h"

int printf[2];

int myfunc(){ // Just for example
printf[0] = 0;
return printf[1];

$ cat main.c
#include <stdio.h>
#include "mylib.h"

int main(){
printf("Helo World!");
return 0;

$ cat Makefile
exec: main mylib
gcc main.o mylib.o -o exec

main: main.c
gcc main.c -c -o main.o

mylib: mylib.c
gcc mylib.c -c -o mylib.o

And here are the results:
$ make
gcc main.c -c -o main.o
gcc mylib.c -c -o mylib.o
mylib.c:3: warning: built-in function 'printf' declared as non-
gcc main.o mylib.o -o exec

$ ./exec
Segmentation fault (core dumped)

$ gdb ./exec core
Core was generated by `./exec'.
Program terminated with signal 11, Segmentation fault.
#0 0x0000000000600884 in printf ()

Thanks in advance,

Cristóvão Sousa
ISR - FCT - University of Coimbra
Mar 5 '08 #1
0 1065

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

Similar topics

by: qazmlp | last post by:
const has internal linkage in C++, but external linkage in C. Am I right ? But, linker reports multiply-defined error if the following header is included in multiple .cpp files. //...
by: Nimmi Srivastav | last post by:
Once and for all can someone kindly tell me the difference between C and C++ linkage. I thought I understood it till someone showed me the other day that C functions, that would ordinarily require...
by: Richard Hayden | last post by:
Hi, I have the following code: /******************************** file1.c #include <iostream> extern void dummy(); inline int testfunc() {
by: Ian | last post by:
The title says it all. I can see the case where a function is to be called directly from C, the name mangling will stuff this up. But I can't see a reason why a template function can't be...
by: Mark A. Gibbs | last post by:
I have a question about mixing C and C++. In a C++ translation unit, I want to define a function with internal linkage and C calling convention. Here's a sample of what I want to do: //...
by: Sune | last post by:
Hi, previously I used Eclipse CDT for compiling my files just to get started with C and leave C++ behind. Now it's time to get a little more serious so I've moved my files to a new workplace and...
by: al.cpwn | last post by:
do static and inline functions or members have internal linkage? I have been reading this newsgroup on google and found conflicting ideas. Can someone please help me understand why in some places...
by: Your Uncle | last post by:
I'm given to understand that your standard is specific regarding linking to c. Furthermore I'm going to speculate that there exists a c++ version of Keith Thompson, brilliant, encyclopedic and...
by: robert maas, see http://tinyurl.com/uh3t | last post by:
Here's the source: #include <stdio.h> #include <errno.h> main () { char* str = "9999999999"; long long int llin; char* endptr; /* Set by strtoll */ int nch; errno = 0; llin = strtoll(str,...
by: Nagrik | last post by:
Dear Group, The book of Bjarne Stroustrup in chapter 5.4.4 says the following "The word static is one of the most overused words in C and C++. For static data members it has both of the...
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

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.