Monthly Archives: May 2014

undefined reference to `SetDIBitsToDevice@48′

from [1]一样的问题, 添加后解决
Hello,Recently I’ve downloaded Code::Blocks because I’d like to make projects that are open and multi platform. I want to make a very simple program that uses the C image liberary CImg.
The whole library is included in a single header called :CImg.h”. I’ve included this in the same folder as my project I wish to work on. I have also included the header file in my source code for the project.

The minimum code contained in my main.cpp file looks like this:

#include"CImg.h"usingnamespace cimg_library;int main(){constunsignedchar purple[]={255,0,255};CImg<unsignedchar>(640,400,1,3,0).draw_text(100,100,"Hello World",purple).display("My first CImg code");return0;}

Upon compiling I get the following errors:


obj\Release\main.o:main.cpp||undefined reference to `SetDIBitsToDevice@48'|
obj\Release\main.o:main.cpp|| undefined reference to `SetDIBitsToDevice@48'|
obj\Release\main.o:main.cpp|| undefined reference to `SetDIBitsToDevice@48'|
obj\Release\main.o:main.cpp||undefined reference to `SetDIBitsToDevice@48'|
obj\Release\main.o:main.cpp|| undefined reference to `SetDIBitsToDevice@48'|
obj\Release\main.o:main.cpp|| more undefined references to `SetDIBitsToDevice@48' follow|||===Build finished:6 errors,0 warnings ===|

I’m not used to really working much with external dependencies with Code::Blocks and I’ve not ventured beyond playing with SFML (which I got working following a tutorial).
I’m working on Windows 7 at the moment if that is of any help. I’m not advanced with C++ but I have an understanding of the core library. Adding dependent libraries is really a headache it seems…

Sponsor:

#2Ryan Konky   Members   –  Reputation: 95

Like

0Likes1Likes

Like

Posted 10 June 2011 – 07:58 AM

Although I don’t know CImg, undefined reference normally means you haven’t linked something properly.Meaning, either it’s not there (under more options in build options), in the wrong order or the library files is not in the places where you have specified. (MinGW compiler library folder or somewhere else on your hard drive).

Sometimes, particularly with things like Qt4 and Java, you may need to setup Environmental Variables under Advanced Properties in Computer; this is for in folders other than the MinGW library folder.

My TwitterI do not care for reputation, merely to help fellow users.

#3nife87   Members   –  Reputation: 516

Like

0Likes1Likes

Like

Posted 10 June 2011 – 08:06 AM

A quick search on Google (SetDIBitsToDevice) revealed that you need to link with libgdi32.a (assuming MinGW). Under Build Options – Linker Settings – Link Libraries, add gdi32.

#4Ryan_Burnside   Members   –  Reputation: 106

Like

0Likes1Likes

Like

Posted 10 June 2011 – 07:29 PM

‘nife87’, on 10 Jun 2011 – 10:06 PM, said:

A quick search on Google (SetDIBitsToDevice) revealed that you need to link with libgdi32.a (assuming MinGW). Under Build Options – Linker Settings – Link Libraries, add gdi32.

Thank you SO much!
Working now!

What is a general rule of thumb process when adding a new library to a project?
It seems that no two libraries share exactly the same steps…

#5nife87   Members   –  Reputation: 516

Like

1Likes2Likes

Like

Posted 11 June 2011 – 07:09 PM

Rule of thumb: Include as few headers as possible, and link as few libraries as possible :wink:As mentioned, most “undefined reference to SomeFunction@XX” are linker errors (the value XX indicates how many bytes of parameters it expects), and if you do not know which library it is defined within, you will just have to search (Google is your friend) or look in the source. Chances are, you are not the first to ask this question, or it will be documentated somewhere online, as the aforementioned function were on MSDN.

When you want to use a new library, you have usually read an article/tutorial about it, so you will know what functions/classes to use, which basic headers to include and which libraries to link with. The latter is only an option when someone have been so kind as to compile them for you – otherwise this you will also have to do yourself (can be a bit tricky if you also have to guess the compiler and linker parameters).
Now, whether you have read about its usage or not, it is always a good thing to get an overview of the library’s general structure, since no two libraries are the same (as you have discovered). This will also give you an understanding of its usage and a clue as to how it works internally (can be useful when strange errors start to pop up). Just a quick look through the API Reference (Doxygen) or similar will usually do (heck, even scanning the main “include” directory reveils a lot about its structure if the headers are properly named).

[1] http://www.gamedev.net/topic/603840-codeblocks-cimg/

C++ undefined reference to WinMain@16 (Code::Blocks)

同样的问题,

http://stackoverflow.com/questions/21500724/c-undefined-reference-to-winmain16-codeblocks

解决方案为

Try this: Settings->Compiler, click the tab Build options, select the checkbox

Explicitly add currently compiling file’s directory to compiler search dirs

P.S.

Next time when you create a new class, in the File policy section, make sure you select checkboxes

  • Add path to project
  • Header and implementation file shall be in same folder

However, do NOT select

Use relative path

stay uncomfortable 不要在舒适区呆着

Women Techmakers Summit – Staying Uncomfortable: How I Got to Design Glass featuring Isabelle Olsson

https://www.youtube.com/watch?v=JXWJN0DtH2c&list=UU_x5XG1OV2P6uZZ5FSM9Ttw

来自Google Glass的主要设计师 Isabelle Olsson 的分享, 不要呆在自己的舒适区, 要勇于挑战并且呆在不舒适区, 才能够达成一些刚开始看起来不能完成但最终被证实非常有影响力的事情.

想起了9gag上的一个图[1]和另外一个地方的图[2], 表达了相似的含义, 共勉, 在保证身体健康情况下, 走出comfort zone, 尝试不可能

[1] http://9gag.com/gag/4578361/your-comfort-zone-vs-where-the-magic-happens

[2] http://wishesforthesoul.files.wordpress.com/2013/08/4397d05310079996d45c3e85f5af2b63.jpg

开心一笑6

One joke a day, keeps the doctor away.

———————————————-

[看到一个妹子,身材好,跟叶说这个妹子我见过两次,这次穿的最保守,blah blah]

叶:这妹子有这么好看么

我:很爽的 blah blah blah

叶:你的精虫溢出到眼睛已经把你的晶状体顶住了,你的晶状体像差太大了,本来是B的看成D了,完全是这样的

我:。。。。。。。。。。。。

 

 

 

 

——————————————

maybe

开心一笑5

One joke a day, keeps the doctor away.

————————————————-

[我用耳机听音乐,叶看到,问型号,我说不记得了,是打折时候买的]

我:几十刀吧应该,不记得了,肯定是打折

叶:你就没想过为啥打折?

我:反正我不是你那种金耳朵,没差别

叶:差评攒到5000终于可以打!折!啦!

开心一笑4

One joke a day, keeps the doctor away.

————————————————-

[今天去食堂吃饭路上,看到一个走路看起来很不正常的猫咪,好像脊椎断过]

我:这个猫咪走路有点奇怪啊

叶:脊椎断过嘛看起来

叶:肯定是TA跳阳台,高呼:九!条!命!

。。。。。。。。。。。。

然后就断了

开心一笑3

One joke a day, keeps the doctor away. —————————————–

[移动上网速度太慢,所以就加了个联通卡,由于不是双卡双待手机,就加了个黑莓手机放移动卡,n5放联通]

 

老婆:以后叫你双机辐射小王子^_^

开心一笑2

One joke a day, keeps the doctor away.

—————————————–

[今天带着老婆骑车,骑在路边上,此为背景]

老婆:啊,后面有个车,小心点,

老婆:是别克,

老婆:别克斯洛伐克

——————————————

哈哈哈哈哈哈哈哈哈哈哈哈哈

养个神经病一样的老婆有时候还真好玩呢

开心一笑

One joke a day, keeps the doctor away.

_______________________________

老婆:(拿着纸巾在仔细擦拭手机)

我:(疑惑的望着她)

老婆:你不知道么,我每天都要擦手机

我:(我对你的干净的追求表示钦佩并无语中)

老婆接着说:手机比厕所还脏!!!

我:那这么说的话,我每天抱着坨粑粑在床上玩儿………

两人一想,遂哈哈哈大笑,笑了半分钟

老婆:我好奇的想象了下你抱着粑粑在床上的情景………

复哈哈哈哈大笑一分钟