Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GMT fails to build with gcc 10 #2493

Closed
opoplawski opened this issue Jan 23, 2020 · 17 comments
Closed

GMT fails to build with gcc 10 #2493

opoplawski opened this issue Jan 23, 2020 · 17 comments

Comments

@opoplawski
Copy link

Description of the problem

gcc 10 has landed in Fedora Rawhide, and it now defaults to -fno-common. As a result GMT fails to build with:

/usr/bin/ld: CMakeFiles/supplib.dir/potential/gmtgravmag3d.c.o:/builddir/build/BUILD/gmt-6.0.0/src/potential/okbfuns.h:43: multiple definition of `okabe_mag_param'; CMakeFiles/supplib.dir/potential/okbfuns.c.o:/builddir/build/BUILD/gmt-6.0.0/src/potential/okbfuns.h:43: first defined here
/usr/bin/ld: CMakeFiles/supplib.dir/potential/gmtgravmag3d.c.o:/builddir/build/BUILD/gmt-6.0.0/src/potential/okbfuns.h:47: multiple definition of `okabe_mag_var'; CMakeFiles/supplib.dir/potential/okbfuns.c.o:/builddir/build/BUILD/gmt-6.0.0/src/potential/okbfuns.h:47: first defined here
/usr/bin/ld: CMakeFiles/supplib.dir/potential/grdgravmag3d.c.o:/builddir/build/BUILD/gmt-6.0.0/src/potential/okbfuns.h:47: multiple definition of `okabe_mag_var'; CMakeFiles/supplib.dir/potential/okbfuns.c.o:/builddir/build/BUILD/gmt-6.0.0/src/potential/okbfuns.h:47: first defined here
/usr/bin/ld: CMakeFiles/supplib.dir/potential/grdgravmag3d.c.o:/builddir/build/BUILD/gmt-6.0.0/src/potential/okbfuns.h:43: multiple definition of `okabe_mag_param'; CMakeFiles/supplib.dir/potential/okbfuns.c.o:/builddir/build/BUILD/gmt-6.0.0/src/potential/okbfuns.h:43: first defined here

For example, okabe_mag_param is defined in src/potential/okbfuns.h:

struct MAG_PARAM {
        double  rim[3];
} *okabe_mag_param;

and included in multiple sources rather than declared extern in the header and defined in a single source file.

@PaulWessel
Copy link
Member

Thanks @opoplawski. Hi @joa-quim, perhaps you should fix this? I suggest just having

struct MAG_PARAM {
   double rim[3]
};

in okbfuns.h and then add

struct MAG_PARAM * okabe_mag_param = NULL; in the C codes and then allocate/assign there as needed (same where okabe_mag_var is needed).

@joa-quim
Copy link
Member

Not that simple. I need okabe_mag_param and okabe_mag_var to be global in okbfuns.c

@PaulWessel
Copy link
Member

Well, then figure about a way to avoid global by passing pointers to functions. Globals are bad news.

@joa-quim
Copy link
Member

I've been trying to do that but old convoluted code. The problem is exactly the pointers to functions. See grdgravmag3d.c #L1201-1203. If I pass the above vars via args then the functions signature is no longer equal.

@PaulWessel
Copy link
Member

OK, I will have a look later if I have time. Bloody busy the next week though.

@PaulWessel
Copy link
Member

Looks like there is only one exported function in okbfuns.c called okabe that needs to take two more arguments and that is how you pass in okabe_mag_var and okabe_mag_param allocated in the main into okabe which then needs to pass those pointers into functions it calls, such as okb_mag and okb_grv.

@joa-quim
Copy link
Member

Yes, that would be easy but you haven't looked at my grdgravmag3d reference above

	double (*d_func[3])(struct GMT_CTRL *, double, double, double, double, bool, struct BODY_DESC, struct BODY_VERTS *,
	        unsigned int, unsigned int, struct LOC_OR *);

	/* IDEALY THIS SHOULD BE A MUTEX. BUT FIRST: HOW? AND SECOND, WOULDN'T IT BREAK THE WHOLE TREADING MECHANICS? */
...
	v_func[0] = grdgravmag3d_body_set_tri;
	v_func[1] = grdgravmag3d_body_set_prism;
	v_func[2] = grdgravmag3d_body_set_prism;
	d_func[0] = okabe;
	d_func[1] = mprism;
	d_func[2] = bhatta;

The problem is that the functions mprism and batha functions would get different signatures and hence the *d_func[3] array could no longer be used.

@PaulWessel
Copy link
Member

Well, I think you just add those two args to all those functions and they are just not used in some of them. That way they have the same # and type of args.

@joa-quim
Copy link
Member

and change all the places where those functions are called ad add dumb args. Not nice either.

@PaulWessel
Copy link
Member

Maybe @seisman knows how to have cmake pass -fcommon to the compiler for this supplement.

@seisman
Copy link
Member

seisman commented Jan 24, 2020

Changing CMAKE_C_FLAGS should work, but don't have to make it for only one supplement.

@PaulWessel
Copy link
Member

I worry about adding -fcommon to all, but perhaps no big deal since if I read @opoplawski correctly the default used to be -fcommon. Perhaps the solution for now is to add -fcommon to the CMAKE_C_FLAGS while we in the mean time try to eliminate the nasty duplication.

@opoplawski
Copy link
Author

We can certainly add -fcommon in the Fedora package as well. I just wanted to get this on your radar so that it does get fixed at some point.

joa-quim added a commit that referenced this issue Jan 24, 2020
The 3 tests that are affected by this code change pass, but several other cases are not tested and may reserve (bad) surprises.
joa-quim added a commit that referenced this issue Jan 25, 2020
The 3 tests that are affected by this code change pass, but several other cases are not tested and may reserve (bad) surprises.
@joa-quim
Copy link
Member

@opoplawski #2511 has landed in master. Could you please test if it builds fine now?

@opoplawski
Copy link
Author

It does, thanks!

@PaulWessel
Copy link
Member

Just checking that it passes with -fno-common?

@opoplawski
Copy link
Author

It builds fine with gcc 10, so I would say yes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants