Hello everybody,
I am getting bogged-down by these errors troubling me for the last few days
I am writing a C program with a main and several user-defined functions. One of the user-defined functions calls a Fortran 90 subroutine.
The main definition is as follows
void selfenerg(real, int); /*declaration of function selfenerg*/
int main (int argc, char **argv)
{ ..................
....................
...................
prompt_file = stdout;
in_file = stdin;
out_file = stdout;
if(argc > 1) { /* command line: a.out, or a.out in, or a.out in out */
prompt_file = stderr;
in_file = fopen(argv[1], "r");
assert(in_file != NULL);
}
if(argc > 2) {
out_file = fopen(argv[2], "w");
assert(out_file != NULL);
}
.............................................
............................................
selfenerg(parameters);
.............................
.............................
/*with the user-defined functions*/
void surfGF4_(double*, double*, double*, double*, double*, double*, double*, double*, double*); /* fortran 90 subroutine declaration */
void selfenerg(real d_omega, int len)
{ ........................................
..........................................
...................
surfGF4_(&w, &sigm11[0][0], &sigm12[0][0], &sigm21[0][0], &sigm22[0][0], &sigmN_1N_1[0][0], &sigmN_1N[0][0], &sigmNN_1[0][0], &sigmNN[0][0]);
/*calling fortran 90 function*/
............................................
.............................................
subroutine surfGF4(w, sigm11, sigm12, sigm21, sigm22, sigmN_1N_1, sigmN_1N, sigmNN_1, sigmNN)
implicit none
.................................................. ....
.................................................. ....
I compile these main c subroutine and fotran 90 programs using Linux commands
pgf90 -c surfGF4.f90
icc -c GlobalRevo.c .../.../....(extension to handle fast fourier transform)
pgf90 surfGF4.o GlobalRevo.o ...../...../.(extension to handle fast fourier transform)
sometimes I remove the extension from the second line
I also try to use ifort instead of pgf90, but in either case I encounter the following errors
GlobalRevo.o: In function `main':
GlobalRevo.c:(.text+0x0): multiple definition of `main'
/share/intel/9.1-x86_64/fce/9.1.051/lib/for_main.o:: first defined here
ld: Warning: size of symbol `main' changed from 70 in /share/intel/9.1-x86_64/fce/9.1.051/lib/for_main.o to 2354 in GlobalRevo.o
/share/intel/9.1-x86_64/fce/9.1.051/lib/for_main.o: In function `main':
: undefined reference to `MAIN__'
GlobalRevo.o: In function `retardselfenerg':
GlobalRevo.c:(.text+0x419d): undefined reference to `surfGF4_'
GlobalRevo.c:(.text+0x4449): undefined reference to `surfGF4_'
GlobalRevo.c:(.text+0x46f5): undefined reference to `surfGF4_'
GlobalRevo.c:(.text+0x49a1): undefined reference to `surfGF4_'
GlobalRevo.c:(.text+0x4c4d): undefined reference to `surfGF4_'
GlobalRevo.o:GlobalRevo.c:(.text+0x4ef9): more undefined references to `surfGF4_' follow
So, the major errors listed here include multiple definition of 'main', undefined reference to 'main' and undefined reference to 'surfGF4_'(the fortran 90 subroutine that is called by the main c program)
I have not fully understood a main of type
int main (int argc, char **argv), especially the two arguments shown here
I try to change this main header to the simpler form like
int main (void)
but it does not help either
Anyone can help me address the errors here?
Thanks
4 3046
You can use:
or -
int main (int argc, char **argv)
-
{
-
-
}
-
depending upon whether you use argc or argv.
However, this error:
GlobalRevo.c:(.text+0x0): multiple definition of `main'
says there are multiple main functions in GlobalRevo.c.
The surfGF4 function must be in a library. Do you have the Fortran library with this function in your make file??
I can't tell from your code where main ends exactly.
You can use:
or -
int main (int argc, char **argv)
-
{
-
-
}
-
depending upon whether you use argc or argv.
However, this error:
GlobalRevo.c:(.text+0x0): multiple definition of `main'
says there are multiple main functions in GlobalRevo.c.
The surfGF4 function must be in a library. Do you have the Fortran library with this function in your make file??
I can't tell from your code where main ends exactly.
The main program ends after the 2 dashed-lines before /* with the user defined function*/
fortran 90 subroutine 'surfGF4' is my own fortran code, it uses no fortran library functions at all
I have checked that all the user-defined functions have been called at least once from the main program. The reason is, I am worried if one or more of these user-defined functions is not called by the main at least once, then the compiler will think that the function is just another main. Is it a correct surmise?
I am concerned if a user defined function in C should not call another user-defined function/subroutine just as 'selfenerg' does here. If indeed it shouldn't, the failure of 'selfenerg' to call 'surfGF4' may be not surprising and also since they are written in different languages. Does it seem a plausible explanation and what may be the possible solution?
Thanks
There is a documented standard for the calling conventions in C. If I remember, C uses the same conventions as Fortran. Therefore, youcan call a Fortran function in C.
To do that you need a) a header file with the C function protoype, b) a library containing the the compiled code for the Fortran library.
Do you have that lilbrary? If so, it needs to be added to your make as an additional linker dependency.
The reason is, I am worried if one or more of these user-defined functions is not called by the main at least once, then the compiler will think that the function is just another main. Is it a correct surmise?
No. main is known as main. You can have only one.
Funcitons are called by name.
The compiler never sees these functions. All it sees is the function prototype.
The compiler just notes that the function is an "unresolved external reference" but does not produce an error. It is the job of the linker to locate that function.
If indeed it shouldn't, the failure of 'selfenerg' to call 'surfGF4' may be not surprising and also since they are written in different languages.
Who cares. Once a function is compiled to binary the language it was written in is irrelevant.
Again, The C side needs a C function prototype and a binary of the compiled function. This is usually supplied as a library. I may not be correct, but I believe you can use a Fortran library as input to the C linker.
This code:
subroutine surfGF4(w, sigm11, sigm12, sigm21, sigm22, sigmN_1N_1, sigmN_1N, sigmNN_1, sigmNN)
looks different on the C side. w and sigm11 are addresses. yes?? Because the C call is looking for double*.
Hello everybody,
I am getting bogged-down by these errors troubling me for the last few days
I am writing a C program with a main and several user-defined functions. One of the user-defined functions calls a Fortran 90 subroutine.
The main definition is as follows
void selfenerg(real, int); /*declaration of function selfenerg*/
int main (int argc, char **argv)
{ ..................
....................
...................
prompt_file = stdout;
in_file = stdin;
out_file = stdout;
if(argc > 1) { /* command line: a.out, or a.out in, or a.out in out */
prompt_file = stderr;
in_file = fopen(argv[1], "r");
assert(in_file != NULL);
}
if(argc > 2) {
out_file = fopen(argv[2], "w");
assert(out_file != NULL);
}
.............................................
............................................
selfenerg(parameters);
.............................
.............................
/*with the user-defined functions*/
void surfGF4_(double*, double*, double*, double*, double*, double*, double*, double*, double*); /* fortran 90 subroutine declaration */
void selfenerg(real d_omega, int len)
{ ........................................
..........................................
...................
surfGF4_(&w, &sigm11[0][0], &sigm12[0][0], &sigm21[0][0], &sigm22[0][0], &sigmN_1N_1[0][0], &sigmN_1N[0][0], &sigmNN_1[0][0], &sigmNN[0][0]);
/*calling fortran 90 function*/
............................................
.............................................
subroutine surfGF4(w, sigm11, sigm12, sigm21, sigm22, sigmN_1N_1, sigmN_1N, sigmNN_1, sigmNN)
implicit none
.................................................. ....
.................................................. ....
I compile these main c subroutine and fotran 90 programs using Linux commands
pgf90 -c surfGF4.f90
icc -c GlobalRevo.c .../.../....(extension to handle fast fourier transform)
pgf90 surfGF4.o GlobalRevo.o ...../...../.(extension to handle fast fourier transform)
sometimes I remove the extension from the second line
I also try to use ifort instead of pgf90, but in either case I encounter the following errors
GlobalRevo.o: In function `main':
GlobalRevo.c:(.text+0x0): multiple definition of `main'
/share/intel/9.1-x86_64/fce/9.1.051/lib/for_main.o:: first defined here
ld: Warning: size of symbol `main' changed from 70 in /share/intel/9.1-x86_64/fce/9.1.051/lib/for_main.o to 2354 in GlobalRevo.o
/share/intel/9.1-x86_64/fce/9.1.051/lib/for_main.o: In function `main':
: undefined reference to `MAIN__'
GlobalRevo.o: In function `retardselfenerg':
GlobalRevo.c:(.text+0x419d): undefined reference to `surfGF4_'
GlobalRevo.c:(.text+0x4449): undefined reference to `surfGF4_'
GlobalRevo.c:(.text+0x46f5): undefined reference to `surfGF4_'
GlobalRevo.c:(.text+0x49a1): undefined reference to `surfGF4_'
GlobalRevo.c:(.text+0x4c4d): undefined reference to `surfGF4_'
GlobalRevo.o:GlobalRevo.c:(.text+0x4ef9): more undefined references to `surfGF4_' follow
So, the major errors listed here include multiple definition of 'main', undefined reference to 'main' and undefined reference to 'surfGF4_'(the fortran 90 subroutine that is called by the main c program)
I have not fully understood a main of type
int main (int argc, char **argv), especially the two arguments shown here
I try to change this main header to the simpler form like
int main (void)
but it does not help either
Anyone can help me address the errors here?
Thanks
Put the statement return 0;
before closing the main.
You must have one and only one main() function in your program
Even though you keep them in different files; if you include another
file which also contains main then it will be a conflict to the compiler from
where to start with.
Avoid such things and have only one main() function.
Regards,
Girish.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: DanielBradley |
last post by:
Hello all,
I have recently been porting code from Linux to cygwin and came across
a problem with static const class members (discussed below). I am
seeking to determine whether I am programming...
|
by: Thomi Richards |
last post by:
Hi,
I'm trying to create a simple stack class using C++ and templates.
Everything works well and good if I amke the class totally inline.
However, as soon as I try to seperate the class into a...
|
by: prasanna |
last post by:
i will be very thankful if you sent all the errors and warnings regarding
to the language C
thank you
|
by: Massimo Soricetti |
last post by:
Hello,
I'm not a C newbie, but I'm teaching C programming (well... FIRST
programming and then C) to other guys these days and it's driving me to
some reflexions on the language.
It's not...
|
by: errmaker |
last post by:
hi
i have msdn tcp/ip sample :
#include "stdafx.h"
//int _tmain(int argc, _TCHAR* argv)
//{
// return 0;
|
by: dasilva109 |
last post by:
Hi guys
I am new to C++ and need urgent help with this part of my code for a
uni coursework I have to submit by Thursday
//ClientData.h
#ifndef CLIENTDATA_H
#define CLIENTDATA_H
#include...
|
by: Andrew |
last post by:
Hi, I am trying to write a program to solve roots using the Newtonian
method of roots, and I am recieving several errors which I cannot
figure out... if anyone could give me a point in the right...
|
by: RK |
last post by:
I renamed a function in one of my files, and got this error (gcc
4.0.1, Apple build 5367)--
c++ -O2 -o cantilever Force.cpp Beam.cpp CantileverNl.cpp main.cpp
/usr/bin/ld: multiple definitions...
|
by: Dan |
last post by:
Hi All,
I've got a problem with my C++ application that calls a Java class
that I've built with GCJ, I can't run it because I get errors:
multiple definition of `atexit'
first defined here...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: Mushico |
last post by:
How to calculate date of retirement from date of birth
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: Aliciasmith |
last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
|
by: tracyyun |
last post by:
Hello everyone,
I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
|
by: giovanniandrean |
last post by:
The energy model is structured as follows and uses excel sheets to give input data:
1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
|
by: NeoPa |
last post by:
Hello everyone.
I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report).
I know it can be done by selecting :...
| |