Now, I have changed the code in the file.h as:
Now, my question is, if I want to print the value of i before calling the foo() function in the file2.c, what should I do in order to not to end up in the linker error?
// file2.c
Last edited by royalibrahim; 03-27-2013 at 02:54 AM..
If you have the "extern int i" declaration in your file.h then I do not see why you would still get the multiple definition error...because the i in file2.c inside main is unrelated to the i in file1.c inside foo which in turn is unrelated to the global i that is defined in file2.c.
You have to look at the way the different variables are setup in the segments to understand the linkages between them. The global i defined in file2.c lies in the data segment and is unrelated to the local i inside main within the file2.c which lies on the stack frame created for main...similarly the local i inside foo of file1.c lies in the stack frame created for foo and is unrelated to the global i or the i that is local to main...let me know if this helps or if i have managed to confuse you even more
You have to look at the way the different variables are setup in the segments to understand the linkages between them. The global i defined in file2.c lies in the data segment and is unrelated to the local i inside main within the file2.c which lies on the stack frame created for main...similarly the local i inside foo of file1.c lies in the stack frame created for foo and is unrelated to the global i or the i that is local to main...let me know if this helps or if i have managed to confuse you even more
Your analysis is incorrect. There are no versions of i which are local to a block (function or otherwise). All of those identifiers refer to the same externally-linked, global storage allocation.
Your analysis is incorrect. There are no versions of i which are local to a block (function or otherwise). All of those identifiers refer to the same externally-linked, global storage allocation.
Regards,
Alister
Thanks alister, but when you say so then why in file2.c, the identifier 'i' is not referring to the same externally-linked, global storage allocation as how the file1.c does? that is,
Why I have to allocate a memory for i (declaring an int i) in the global scope in file2.c to get rid of this problem?
Hi,
Currently I am migrating codes from unix to Linux. When doing linking(ld) getting the below error.
Error is :ld: invalid BFD target `--shared'
Providing the script of the ld:
ld -b -G -o lib/libatk.so ./src/atk_db.o ./src/atk_gcl.o ./src/atk_options.o ./src/atk_exception.o... (1 Reply)
I am on a FreeBSD system trying to build a piece of software that I wrote. I had built it in the past but recently reinstalled FreeBSD. I am not sure what is going on. The software depends on and wxgtk2.8.
Using g++:
$ make
g++ -c `wx-config --cxxflags`... (9 Replies)
Hi,
We have installed linux6(RHEL) OS and installed datastage application on that.
First time installation worked fine and our all services related to datastage was up and running.
When we stopped the datastage and restarted its giving below error while restart:-
./uv -admin -start
... (0 Replies)
I have a C binary file(.so as extension) which is delivered by a product.
How do i use this functionalities of this .so file in my C program?
How can in link the .so to my C program? (1 Reply)
Hello. This shouldn't be an unusual problem, but I cannot find anything about it at google or at other search machine.
So, I've made an application using C++ and QtCreator. I 've made a new mime type for application's project files.
My system (ubuntu 10.10), when I right click a file and I... (3 Replies)
Hello,
we are a group of students (mechanical engineering) who are trying to port UNIX-software to a PC Linux system during a study project. The first goals were achieved: compiling the Fortran code and creating object files. However, we encounter errors during the linking process.
This is... (0 Replies)
Hi,
I got a script which sends the Email to the user based on certain variables received from Tivoli Server Monitoring 6.1.
Now to keep track of the mails I have wrote a stored procedure in DB2 as we use DB2 UDB as back end which take the variables that were used to send the mail and store it... (3 Replies)
Getting the following error ,
ld: /opt/syncsort39/lib/libsyncsort.sl: Mismatched ABI. 64-bit PA shared library found in 32-bit link.
Is there any difference in the ld options in opt file while linking a 64 bit shared library ? Or is the problem because we are trying to link both 32 bit and 64... (3 Replies)
Hi
I'm getting
ld: fatal: option -h and building a dynamic executable are incompatible
ld: fatal: Flags processing errors
When I run
ld -shared -L/usr/dt/lib -lDtSvc -o builtin.so Workspace.o
after running
gcc -fPIC -I/usr/X11R6/include -I/usr/dt/include -c Workspace.c
I'm... (6 Replies)