Vladimir Marek wrote:

> 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 ...

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 -- [email protected] -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/202109171845.18HIjshx2253685%40masaka.moolenaar.net.

Raspunde prin e-mail lui