g ++与DevIL:无法链接 [英] g++ with DevIL: unable to link

查看:299
本文介绍了g ++与DevIL:无法链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我使用Fedora和学习OpenGL。我想与DevIL一点工作,所以我从官方存储库安装了DevIL和DevIL-ILUT包。我有一个测试代码加载和渲染一个文件可用,所以我决定测试它(我会在我的课程中学习一些DevIL基础知识,我们得到了该文件,以确保DevIL工作正常)。

Firstly, I am using Fedora and learning OpenGL. I would like to work with DevIL a little, so I installed both DevIL and DevIL-ILUT packages from the official repository. I have a test code for loading and rendering a file available, so I decided to test it (I will be learning some DevIL basics at my course, and we were given that file to make sure DevIL works fine for us).

文件包含行:

#include "IL/devil_cpp_wrapper.hpp"

所以我将IL目录(我们也可用)复制到测试文件目录包含很多头文件,例如il.h,ilut.h,ilu.h,...)。但是,构建失败的

so I copied the IL directory (which we also have available) to the directory with test file (IL directory contains a lot of header files, for example il.h, ilut.h, ilu.h, ...). However, the build failed at

#include <IL/ilut.h>

。我没有得到它,因为我安装了包。我尝试把每一个可能的参数到g ++(因为我没有找到任何有用的手册,也许我只是盲),-lIL,-lILU,-lILUT,-ldevil,为每一种可能性,它给我相同的错误。我找不到任何正确的解决方案,所以我放弃了并复制IL目录也到/ usr / include。这一次它给每个库包括这个错误:

from the IL/devil_cpp_wrapper.hpp file. I don't get it, since I installed the packages. I tried putting every possible parameter to g++ (since I didn't find any useful manual for it, maybe I am just blind), -lIL, -lILU, -lILUT, -ldevil, for every possibility it gives me the same error. I wasn't able to find any proper solution, so I gave up and copied the IL directory also to /usr/include. This time it gave me this error for every library included:

/usr/bin/ld: cannot find <param>

所以我删除了目录,并尝试将所有系统包括devil_cpp_wrapper.hpp在目录中(因为文件被调用相同)。链接器有相同的问题,所以我删除所有库参数,并尝试再次编译,这次失败的未定义的引用为DevIL特定的函数。

So I deleted the directory, and tried replacing all system includes like the one in devil_cpp_wrapper.hpp by ones in the directory (since the files are called the same). The linker had the same issue, so I removed all library params and tried compiling it again, this time failing on "undefined reference" for DevIL-specific functions.

还有一些文件dll(DevIL.dll,ILU.dll,ILUT.dll)和.lib给他们,我试图链接他们,但仍然得到相同的未定义的引用错误。此外,本课程主要是为VS用户,所以我不知道应该包括哪些文件。

We have available also some files for dll (DevIL.dll, ILU.dll, ILUT.dll) and .lib to them, I tried linking also them, but still get the same undefined reference errors. Also, this course is made mainly for VS users, so I am not sure which files I should include.

我也尝试从他们的github源构建DevIL他们的README.unix文件,但在第一步失败(autoreconf -i失败的一些libILUT.la;我也尝试了autoconf -i,如果他们写错了,它失败了未定义的win32宏)。

I also tried building DevIL from their github source as is written in their README.unix file, but failed on the first step (autoreconf -i was failing for some libILUT.la; I tried also autoconf -i in case they have written it wrong, it failed for undefined win32 macro).

所以,我的问题是:我是一个noob谁不能链接DevIL。我尝试了我可以想到的一切,但找不到任何解决方案。任何人都可以帮助我?

So, my question is: I am a noob who can't link DevIL. I tried everything I could think of, but can't find any solution. Can anyone help me?

编辑:因为从github的构建失败,我决定给它一个机会,下载他们的.tar,并试图从中编译。它似乎在工作,但是然后使返回未定义引用`png_set_gray_1_2_4_to_8和collect2:错误:ld返回1退出状态。即使在这之后,我试图用make install完成构建,这当然失败,但在这个尝试中,我有一些库到/ usr / local / lib。但是,我仍然无法编译我的测试程序,因为上面提到的链接器现在提到的png_set_gray_1_2_4_to_8的引用。

Since the build from github was failing, I decided to give it a chance and download their .tar and tried to compile from it. It seemed to be working at first, but then make returned "undefined reference to `png_set_gray_1_2_4_to_8'" and "collect2: error: ld returned 1 exit status". Even after this I tried to complete the build with make install, which of course failed too, but in this attempt I got a few libraries into /usr/local/lib. However, I still can't compile my test program, because the mentioned undefined reference to png_set_gray_1_2_4_to_8, which the linker complains about now.

推荐答案

p>在Linux上使用库有很多选项。

There are plenty of options for using libraries on Linux. It's usually fairly easy, but you seem to have stumbled on some of the common gotchas.

/ usr 目录用于系统安装的软件包(例如Debian,Ubuntu或Mint上的 apt-get ),

The /usr directory is for packages installed by the system (e.g. apt-get on Debian, Ubuntu, or Mint), so you should almost never touch it at all.

/ usr / local 目录适用于安装(假设您是计算机的管理员),但您不手动复制文件。

The /usr/local directory is for packages that you install (assuming that you are the administrator of the machine), but you don't manually copy files there. Instead, you run installation scripts that put files there automatically.

通常,安装方式如下:

./configure
make
sudo make install



< h2>规则#2:首先使用包管理器。

包管理器取决于您使用的Linux发行版。例如,在基于Debian的系统上,软件包系统是apt,你可以使用synaptic,aptitude或apt-get来安装软件包。

Rule #2: Use the package manager first.

The package manager depends on which Linux distro you are using. For example, on Debian-based systems, the package system is "apt", and you can use synaptic, aptitude, or apt-get to install packages.

系统,我将运行命令:

sudo apt-get install libdevil-dev

-dev 表示开发,因此它包括您需要编译程序使用DevIL。

The -dev means "development", so it includes the headers you need to compile programs that use DevIL.

正确的版本会有 configure 脚本。因为你从GitHub下载,你必须调用 autoconf ,这意味着在你的系统上安装更多的软件包。

Proper releases will have configure scripts. Because you downloaded from GitHub, you had to invoke autoconf, which just means installing more packages on your system. Don't bother, just grab a proper source code release.

你没有提到你是如何编译的,所以它让我担心你可能只是在命令行中输入 gcc

You haven't mentioned how you're compiling things, so it makes me worried that you might just be typing gcc on the command line. This is a recipe for frustration.

下面是一个makefile,你可以使用它来编译一个使用DevIL的简单C ++程序,假设你的程序都在 main.cpp

Here is a makefile that you can use to compile a simple C++ program that uses DevIL, assuming your program is all in main.cpp:

all: myprog
clean:
    rm -f myprog *.o

devil_cflags := $(shell pkg-config --cflags IL)
devil_libs := $(shell pkg-config --libs IL)

CXXFLAGS := -O0 -g -Wall -Wextra $(devil_cflags)
LIBS := $(devil_libs)

myprog: main.o
    c++ $(LDFLAGS) -o $@ $^ $(LIBS)

pkg-config 找出如何链接到DevIL。

This uses pkg-config to figure out how to link with DevIL. It's much better than writing the linker flags yourself.

请注意,Makefile中的缩进必须使用制表符,你不能使用

Note that the indentation in a Makefile must be done with tabs, you can't use spaces.

这篇关于g ++与DevIL:无法链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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