如何将.lib与“Visual C ++ for linux”一起使用?插入? [英] How do I use a .lib with the "Visual C++ for linux" plugin?

查看:228
本文介绍了如何将.lib与“Visual C ++ for linux”一起使用?插入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Visual C ++ for Linux插件。我可以毫无问题地运行一个基本的Hello世界。我的实际项目使用 .lib 。它编译的很好,但在链接过程中出现错误(这是从Visual Studio的输出窗格复制的):

  ClCompile:
启动远程构建
编译源:
调用g ++
g ++ -c -x c ++ /home/devbox/projects/LinuxProgServ/LinuxProgServ/main.cpp -I / home / devbox / projects / LinuxProgServ / include / libuv -I /home/devbox/projects/LinuxProgServ/../include/lubuntu -I/home/devbox/projects/LinuxProgServ/../include/lubuntu/x86_64-linux-gnu-g2 - gdwarf-2 -o/home/devbox/projects/LinuxProgServ/obj/x64/Debug/main.o-Wall -Wswitch -Wno-deprecated-declarations-Wempty-body-Wconversion -W返回类型-Wparentheses -W无格式-Wuninitialized -W无法访问代码-W未使用函数-W未使用值-W未使用变量-O0 -fno-strict- aliasing -fno-omit -frame-pointer -fthreadsafe-statics -fexceptions -frtti -std = c ++ 11
main.cpp
完成编译'/ home / devbox / projects / LinuxProgServ / LinuxProgServ / main .cpp'
链接:
Linki ng对象
调用ld
g ++ -o/home/devbox/projects/LinuxProgServ/bin/x64/Debug/LinuxProgServ.out-Wl, - no-undefined / home / devbox / projects / LinuxProgServ / obj / x64 / Debug / main.o -llibuv.lib
/ usr / bin / ld:找不到-llibuv.lib
collect2:错误:ld返回1退出状态

libuv.lib在项目属性>链接器>输入>库依赖关系中指定。我尝试了以下方法但未成功:


  1. 将lib复制到/ home / devbox / projects / lib并将该目录添加到

    链接器命令与-L,都使用Visual Studio的额外的
    库文件夹字段,并直接在附加命令行

    选项字段中。这导致相同的最终命令。
  2. 将lib复制到输出目录并将其设置为复制

  3. 将本地Windows路径添加到Visual Studio的其他库文件夹
  4. 将#1的linux路径添加到Visual Studio的其他库文件夹中

  5. 使用其他库尝试

我为Windows做了同样的项目,只是为了确保它正常工作。



我是否缺少什么?显然,我可以自己运行这些命令或使用* make的任何变体,但那不是重点。 当你通过一个使用 -l <​​/ code>,g ++有助于将给出的名称前缀给 lib ,然后查找具有该名称的文件在库搜索路径中使用 .so .a 扩展名。按照惯例,共享库(dll)具有 .so 扩展名和静态库 .a 扩展名。



阻力最小的路径是使用 .a 扩展名来构建库,即 libuv .a 然后将它指定为VCLinux项目库依赖项,如 uv 。像 -L 一样指定库搜索路径,就像你在步骤1中做的那样。

或者,您可以将库的完整路径放在g ++ link命令行上,而不需要 -l <​​/ code>前缀,即 / home / devbox / projects / lib /libuv.lib ,g ++将以与使用其他目标文件相同的方式使用它。通过链接器/所有选项/附加选项设置

更新:反思中,第二种方法不起作用。虽然g ++(gcc)会在使用完全限定路径指定时接受该库作为输入,但该库必须在之后出现用于解析引用的程序对象文件。不幸的是,在VCLinux中不能控制 Additional Options 的位置,它总是将它们放在g ++命令行参数列表的前面,即在目标文件之前, 。 :(b / b)

而且,冒着明显的风险说明,库必须使用g ++在Linux上构建,并且在链接程序时位于g ++可见的路径上。

I'm using the Visual C++ for Linux plugin. I can run a basic Hello world without problems. My actual project uses a .lib. It compiles fine but I get an error during linking (this is copied from Visual Studio's output pane):

ClCompile:
  Starting remote build
  Compiling sources:
  Invoking g++
  g++ -c -x c++ /home/devbox/projects/LinuxProgServ/LinuxProgServ/main.cpp -I /home/devbox/projects/LinuxProgServ/include/libuv -I /home/devbox/projects/LinuxProgServ/../include/lubuntu -I "/home/devbox/projects/LinuxProgServ/../include/lubuntu/x86_64-linux-gnu" -g2 -gdwarf-2 -o "/home/devbox/projects/LinuxProgServ/obj/x64/Debug/main.o" -Wall -Wswitch -W"no-deprecated-declarations" -W"empty-body" -Wconversion -W"return-type" -Wparentheses -W"no-format" -Wuninitialized -W"unreachable-code" -W"unused-function" -W"unused-value" -W"unused-variable" -O0 -fno-strict-aliasing -fno-omit-frame-pointer -fthreadsafe-statics -fexceptions -frtti -std=c++11
  main.cpp
  Done compiling '/home/devbox/projects/LinuxProgServ/LinuxProgServ/main.cpp'
Link:
  Linking objects
  Invoking ld
  g++ -o "/home/devbox/projects/LinuxProgServ/bin/x64/Debug/LinuxProgServ.out" -Wl,--no-undefined /home/devbox/projects/LinuxProgServ/obj/x64/Debug/main.o -llibuv.lib
  /usr/bin/ld: cannot find -llibuv.lib
  collect2: error: ld returned 1 exit status

libuv.lib is specified in Project Properties>Linker>Input>Library Dependencies. I tried the following without success:

  1. Copy the lib to /home/devbox/projects/lib and add that directory to
    the linker command with -L, both using Visual Studio's additional
    library folder field and directly in the Additional command line
    options field. This results in the same final command.
  2. Copy the lib to the output directory and set it to be copied
  3. Add the local Windows path to Visual Studio's additional library folders
  4. Add the linux path from #1 to Visual Studio's additional library folders
  5. Try with another library

I made the same project but for Windows just to be sure and it works.

Am I missing something? Obviously I could just run the commands myself or use any variant of *make but that's not the point.

解决方案

When you pass a library to g++ with -l, g++ helpfully prefixes the name you give with lib then looks for a file of that name with a .so or .a extension on the library search path. By convention, shared libraries (dlls) have the .so extension and static libraries the .a extension.

The route of least resistance would be to build your library with the .a extension, i.e. libuv.a then specify it to the VCLinux project library dependencies as uv. And specify the library search path with -L, as you do in your step 1.

Alternatively, you can put the full path of the library on the g++ link command line, without -l prefix, i.e. /home/devbox/projects/lib/libuv.lib and g++ will use it in the same way it uses other object files. Set via Linker/All Options/Additional Options.
Update: on reflection, this second approach won't work. Although g++ (gcc) will accept the library as an input when specified with its fully qualified path, the library must appear after the program object files for references to be resolved. Unfortunately there is no control over positioning of Additional Options in VCLinux which always puts them at the front of the parameter list on the g++ command line, i.e. before the object file(s). :(

And, at the risk of stating the obvious, the library must be built on Linux with g++ and be located on a path visible to g++ when linking your program.

这篇关于如何将.lib与“Visual C ++ for linux”一起使用?插入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆