Multiply defined longVersion on Solaris

31 views
Skip to first unread message

Vladimir Marek

unread,
Sep 17, 2021, 7:57:54 AM9/17/21
to vim...@googlegroups.com
Hi,

When compiling on Solaris using gcc 10, I am getting this error:

/usr/gcc/10/bin/gcc ... -o gvim ...
ld: fatal: symbol 'longVersion' is multiply-defined:
(file objects/version.o type=OBJT; file objects/main.o type=OBJT);
collect2: error: ld returned 1 exit status
link.sh: Linking failed


I have produced pre-processed sources (gcc -E) and grepped them for
'longVersion' string:

main.E:void init_longVersion(void);
main.E: char *longVersion = <-------------------
main.E: init_longVersion();
main.E: mch_errmsg(longVersion);
main.E: init_longVersion();
main.E: mch_msg(longVersion);

version.E:void init_longVersion(void);
version.E:extern char *longVersion ;
version.E:char *longVersion = "VIM - Vi IMproved " "8" "." "2" " (" "2019 Dec 12" ")"; <------
version.E:init_longVersion(void)
version.E: init_longVersion();
version.E: msg(longVersion);


Looking in the sources my feeling is that longVersion should be defined
in version.c and only declared (using 'extern') in main.c.

Looking into pre-processed main.c I can see:


char *longVersion =
# 1336 "globals.h" 3 4
((void *)0)


And looking at globals.h line 1336:

1335 #else
1336 EXTERN char *longVersion INIT(= NULL);
1337 #endif

If I replace that line with

extern char *longVersion;

I can compile vim just fine. This does not seem to be something solaris
specific, so I have feeling that I am missing something ...

Thanks for VIM!
--
Vlad

Bram Moolenaar

unread,
Sep 17, 2021, 2:46:08 PM9/17/21
to vim...@googlegroups.com, Vladimir Marek
The best solution seems to be to always declare longVersion in
version.c, and always declare it extern in globals.h. Otherwise the
#ifdef gets complicated.

// These are in version.c, call init_longVersion() before use.
extern char *Version;
#if defined(HAVE_DATE_TIME) && defined(VMS) && defined(VAXC)
extern char longVersion[];
#else
extern char *longVersion;
#endif


Besides the change in globals.h, we also need to declare longVersion in
version.c for the case HAVE_DATE_TIME is defined but VMS is not.

strcat(longVersion, ")");
}

# else
char *longVersion = NULL;

void
init_longVersion(void)
{
if (longVersion == NULL)


--
hundred-and-one symptoms of being an internet addict:
30. Even though you died last week, you've managed to retain OPS on your
favorite IRC channel.

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Vladimir Marek

unread,
Sep 18, 2021, 3:01:35 AM9/18/21
to vim...@vim.org
Hi,

Vladimir Marek

unread,
Sep 20, 2021, 6:12:34 AM9/20/21
to Bram Moolenaar, vim...@googlegroups.com
[...]

> The best solution seems to be to always declare longVersion in
> version.c, and always declare it extern in globals.h. Otherwise the
> #ifdef gets complicated.

Your patch works for me, thank you
--
Vlad
Reply all
Reply to author
Forward
0 new messages