Sunday, March 6, 2011

Re: Using VIM with Clang

> Relevant info:
> 0) This is on FreeBSD stable with clang-develop from ports.
> 1) I've checked that compiling with clang++ from the CMD-line works as
> it should.
> 2) Hence clang and clang++ are indeed in $PATH.

Are you using vim from the comandline/in the terminal, or are you using
gvim? If you're using gvim, perhaps the environment is different and
causing problems.

> 3) I've used the vimrc file as provided by the llvm project, see
> https://llvm.org/svn/llvm-project/ll...tils/vim/vimrc

URLs with '...' in them are incredibly unhelpful if anybody wants to
look up what you've referenced!

> *) the above should have worked according to the discussion in the
> llvm mailing-list here: http://markmail.org/message/mq73uxpc...+state:results
> which it doesn't as it still uses gcc to compile.
>
> 4) I have subsequently set which compiler runs by typing :set
> makeprg=clang++ for c++ code (I've also tried :set makeprg=clang
> instead)
>
> It clearly is using clang after this. Unfortunately it I get a strange
> error-message that doesn't happen when compiling the same hello world
> test-code directly from the command line. The output I get is:
> ---
> hello:(.data+0x8): multiple definition of `__dso_handle'
> /usr/lib/crtbegin.o:(.data+0x0): first defined here
> hello: In function `_init':
> (.init+0x0): multiple definition of `_init'
> /usr/lib/crti.o:/usr/src/lib/csu/amd64/crti.S:(.init+0x0): first
> defined here
> hello:(.data+0x0): multiple definition of `__progname'
> /usr/lib/crt1.o:(.data+0x0): first defined here
> hello: In function `_start':
> (.text+0x0): multiple definition of `_start'
> /usr/lib/crt1.o:crt1.c:(.text+0x0): first defined here
> hello: In function `_fini':
> (.fini+0x0): multiple definition of `_fini'
> /usr/lib/crti.o:/usr/src/lib/csu/amd64/crti.S:(.fini+0x0): first
> defined here
> /usr/local/bin/ld: error in hello(.eh_frame); no .eh_frame_hdr table
> will be created.
> clang: error: linker command failed with exit code 1 (use -v to see
> invocation)
> ---
> Which is the point at which I'm stuck (and google doesn't help me).
> I've also tried with a piece of plain c-code instead of cpp, but this
> leads to the same error-message. Hopefully this error-message triggers
> thoughts on what I'm doing wrong here.

It looks to me like you are trying to link an existing executable
(hello), rather than compiling the source code (hello.c) or linking an
object file (hello.o), and so the linker is finding two copies of all
the system stuff: one copy that is in the executable from the last time
it was linked, and one copy from its attempt to compile it in now.
That's my best guess as to what's happening here, but even that's a
pretty long shot, as usually a linker won't do this, I don't think.

> For clarity both the c and cpp-code compile fine with clang directly
> from the commandline. So the problem must be in the way how I call
> clang from vim (using :set makeprg=clang++ or :set makeprg=clang).
> Hopefully somebody knows what the correct way to do this?

It will be easier to know what's going on and pinpoint the problem and
direct you in the right direction if you could fix the links to the
stuff you are using (or if it's short, include it in the body of your
email), and tell us exactly what commands you are running in Vim, and
how you are starting Vim.

Note also, perhaps it would be smarter to use a makefile, that can
invoke the compiler you want, but not require any change of 'makeprg' in
Vim, only possibly :compiler to correctly interpret the messages.

Cheers,

Ben.

--
You received this message from the "vim_use" 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

No comments:

Post a Comment