SFML undefined reference - c++

I tried to link SFML with codeblocks, but I have some errors running the code from tutorial. This is code I tried to write after I saw that the one in tutorial doesn't work:
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
int main()
{
sf::Window w(sf::VideoMode(800,600),"da");
return 0;
}
This is the tutorial I followed.
After I compile the code above it gives me 4 error that say:
||=== Build: Release in SFML1 (compiler: GNU GCC Compiler) ===|
obj\Release\main.o:main.cpp:(.text.startup+0x97)||undefined reference to `_imp___ZN2sf6StringC1EPKcRKSt6locale'|
obj\Release\main.o:main.cpp:(.text.startup+0xc4)||undefined reference to `_imp___ZN2sf9VideoModeC1Ejjj'|
obj\Release\main.o:main.cpp:(.text.startup+0xaa)||undefined reference to `_imp___ZN2sf6WindowC1ENS_9VideoModeERKNS_6StringEjRKNS_15ContextSettingsE'|
obj\Release\main.o:main.cpp:(.text.startup+0xd3)||undefined reference to `_imp___ZN2sf6WindowD1Ev'|
||=== Build failed: 4 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|

You have made an error or have not followed the tutorial to the letter. This can happen. Everyone makes mistakes. Start over completely new and follow that tutorial to the letter. We cannot possibly know which mistake you made, because to do this, we would need to step through this tutorial as well and check if all the steps were followed correctly.
Please note that the latest version is 2.3 so you should follow the 2.3 tutorial.

Related

Code::Blocks, and C++ Compiler problem. cant compile a header

im having problem when compiling C++ source code. that code is a keylogger. at first, i save with .cpp, and try to compile it from terminal using this command
g++ test.cpp
and then the terminal showed me this messages
test.cpp:1:10: fatal error: conio.h: No such file or directory
#include <conio.h>
^~~~~~~~~
compilation terminated.
and this message
test.cpp:2:10: fatal error: windows.h: No such file or directory
#include <windows.h>
^~~~~~~~~~~
compilation terminated.
to fix this, i tried to use a C++ IDE, code::blocks. installed from terminal, and the copy that keylogger source code to code:::blocks. but the IDE shows this message
||=== Build file: Debug in Belajar CPP (compiler: GNU GCC Compiler) ===|
/home/lucky/test.cpp|1|fatal error: conio.h: No such file or directory|
||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
I just don't know how to fix this and how to search the solutions online. because I'm new in using Linux-Mint. Can someone help me to fix this?
First of all, conio.h and windows.h these headers are not supported on linux console.
Alternative is to use NCurses library. It does all the Console realted stuff you could want and is part of the Linux Standard Base ( i.e. available in every distro ).
Include 'ncurses.h' instead.
I hope this will resolve your issue.

(SFML, Code::Blocks) "undefined reference to (...)" error upon Texture.importFromFile(...)

I decided to try out what is depicted in this YouTube video (building a Tetris game with C++) (I
mention the video for reference purposes).
I have Code::Blocks 17.12. I installed SFML (GCC 4.9.2 TDM (SJLJ) - 32-bit) from their download page and since "the compilers have to match 100%" I also installed TDM 4.9.2 (32-bit) from the link also provided on their download page (not before having run into errors from overlooking this detail to some extent), and set it as my compiler in Code::Blocks.
I followed the tutorial on SFML page. I ran into a couple errors but managed to fix them (such as the one mentioned in the previous parenthetical remark... among others). Everything went fine so I moved on to the code as shown in the YouTube video. At the point where the code is
#include <SFML/Graphics.hpp>
#include <time.h>
using namespace sf;
int main()
{
RenderWindow window(VideoMode(320, 480), "window");
Texture t;
t.loadFromFile("images/tiles.png");
Sprite s(t);
while (window.isOpen())
{
Event e;
while (window.pollEvent(e))
{
if (e.type == Event::Closed)
window.close();
}
window.clear(Color::White);
window.display();
}
return 0;
}
(for the record) I get the error
||=== Build: Release in Tetris (compiler: GNU GCC Compiler) ===|
obj\Release\main.o:main.cpp:(.text.startup+0x24c)||undefined reference to `_imp___ZN2sf7Texture12loadFromFileERKNSt7__cxx1112basic_stringIcSt11char_traits
IcESaIcEEERKNS_4RectIiEE'|
||error: ld returned 1 exit status|
||=== Build failed: 2 error(s), 0 warning(s) (0 minute(s), 3 second(s)) ===|
This is my problem.
An answer to a related SO question suggests something that I understand as "you have to use in C::B the same
compiler as the one which was used to compile SMFL". However I think I have ensured that.
Another related SO question I read but cannot understand anything. I am a total
noob to C/C++ and can't do much more than dilligently, thoughtlessly following
the directions as for example were provided in the tutorial in the SFML site... so if anyone can help me, I'd appreciate it -- could it be made to work or will I have to build SFML myself?
EDIT: Here are screenshots for my linker settings.
With this link you provided in the comments, it looks like your linker settings should be the following:
sfml-window-s
sfml-system-s
opengl32
freetype
jpeg
I had an issue similar to this when I was trying to use SFML, and the linker settings in the correct order was the issue.

Problems installing/understanding c++ libraries( novice programmer)

I have just started learning programming, and I am facing troubles adding libraries ( Other than STD libraries) in my programs.
I use codeblocks IDE and I wanted to add a library CImg from the internet.
After reading many threads I have done the following steps however I still get an error loading one of the examples provided CImg people
Downloaded Cimg folder which has a Cimg.h file along with other example files.
Unzip the folder to E drive.
open code blocks>compiler settings(gnu gcc compiler)>search libraries
under search libraries I have compiler tab and linker tab where I have added the path of the downloaded folder.
next when I open an example provided by the developer, build and run it.
The cimg.h file open up and I get the following error:
||=== Build file: "no target" in "no project" (compiler: unknown) ===|
E:\programming\cpp programming\CImg-2.0.0_pre012317\CImg.h||In function 'int cimg_library::cimg::fseek(FILE*, INT_PTR, int)':|
E:\programming\cpp programming\CImg-2.0.0_pre012317\CImg.h|5617|error: '_fseeki64' was not declared in this scope|
E:\programming\cpp programming\CImg-2.0.0_pre012317\CImg.h||In function 'INT_PTR cimg_library::cimg::ftell(FILE*)':|
E:\programming\cpp programming\CImg-2.0.0_pre012317\CImg.h|5626|error: '_ftelli64' was not declared in this scope|
||=== Build failed: 2 error(s), 0 warning(s) (0 minute(s), 10 second(s)) ===|
Please help me out, Also kindly explain to me what I am doing as I have no idea.
EDIT: As pointed out to me in the comments I have changed my compiler to TDM-GCC MinGW 64 bit compiler.
But now I get a different type of error, is it because I havent installed the compiler properly because I can run hello world using this compiler.
the error that i get is :
||=== Build: Debug in hello (compiler: GNU GCC Compiler) ===|
obj\Debug\main.o||In function cimg_library::CImgDisplay::paint()':|
E:\programming\cpp programming\hello\..\CImg-2.0.0_pre012317\CImg.h|9696|undefined reference to__imp_SetDIBitsToDevice'|
||error: ld returned 1 exit status|
||=== Build failed: 2 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
Finally I have found out what were my mistakes and how to correct them.
I was using a 32 bit compiler, So I switched to one for 64 bits.
After that I had not linked gdi32 library. So when I went to linker settings and added gdi32 to linked libraries evrything started to work.
Thank you for helping me out.

'class std::map<std::basic_string<char>, Gui>' has no member named 'emplace'

Hi Guy's looking for some help and can't understand the problem. I'm following this tutorial https://www.binpress.com/tutorial/creating-a-city-building-game-with-sfml-part-8-gui-system/130, I'm using CodeBlocks 13.12 and SFML 2.1 but when I try to compile the code I get this
||=== Build: Debug in Test (compiler: GNU GCC Compiler) ===|
C:\Users\James\Desktop\Summer Repeats 2015\Games Dev 2\Test\src\Game_State_Start.cpp||In constructor 'GameStateStart::GameStateStart(Game*)':|
C:\Users\James\Desktop\Summer Repeats 2015\Games Dev 2\Test\src\Game_State_Start.cpp|100|error: 'class std::map<std::basic_string<char>, Gui>' has no member named 'emplace'|
||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 1 second(s)) ===|
This is the line of code giving me this error.
this->guiSystem.emplace("menu", Gui(sf::Vector2f(192, 32), 4, false, game->stylesheets.at("button"),
{ std::make_pair("Load Game", "load_game") }));
I have CodeBlocks set for C++11 and change SFML to SFML-2.3.1-windows-gcc-4.9.2-mingw-32-bit because I found here saying I have to use g++ 4.8.0 or higher on this page std::map emplace gcc 4.8.2, but still getting the same error, also the website give's me the code to download even though I'm trying to follow it myself , I checked the code, importing into a new project and that didn't work either, So no idea whats wrong. Any help or a point in the right direction would be most appreciated.
Normally I would post this in a comment but I don't have enough rep.
Start a new project and compile and run this code:
#include <iostream>
#include <ostream>
int main()
{
std::cout << __cplusplus << std::endl;
}
If the result printed out is 199711, then it means you're not compiling using the -std=c++11 option. If the result printed out is 201101 then it means you're using an outdated version of the standard library.
Found the solution. I had originally installed codeblocks-13.12mingw-setup, I uninstalled this and installed codeblocks-13.12mingw-setup-TDM-GCC-481. It works now. Thanks for everybody's help.

wininet.h not compiling using GNU GCC compiler with code blocks

i'm getting a peculiar issue when trying to compile my program. I don't have a huge ammount of experience with C++. I'm trying to simple create a function that can FTP put a file upto my plain FTP server. I'm using codeblocks IDE, and the GNU GCC compiler, and in the end, i thought to try a full fledged example i found online to test if it was me writing some silly code. I have installed the windows SDK with all libs, so i can confirm the files are present, and if i build without any code, there is no linker errors.
I copied the OP's code, as it looked fine, and he complained of no such issues.
http://social.msdn.microsoft.com/Forums/en-US/76eb8b89-4b96-41ba-b869-e30711f29256/ftpputfile?forum=vcgeneral
However when i attempt to build my project, i get a plethora of errors:
||=== Build: Debug in uploader (compiler: GNU GCC Compiler) ===|
C:\C++\uploader\main.cpp||In function 'void FileSubmit()':|
C:\C++\uploader\main.cpp|10|warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]|
C:\C++\uploader\main.cpp|11|warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]|
C:\C++\uploader\main.cpp|12|warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]|
obj\Debug\main.o:main.cpp|| undefined reference to `InternetOpenA#20'|
obj\Debug\main.o:main.cpp|| undefined reference to `InternetConnectA#32'|
obj\Debug\main.o:main.cpp|| undefined reference to `FtpPutFileA#20'|
obj\Debug\main.o:main.cpp|| undefined reference to `InternetCloseHandle#4'|
obj\Debug\main.o:main.cpp|| undefined reference to `InternetCloseHandle#4'|
||=== Build failed: 5 error(s), 3 warning(s) (0 minute(s), 1 second(s)) ===|
Any idea what i'm doing wrong here? Do i need to be using certain compiler settings?
For anyone else experiencing this problem.
The solution to this, as implied by Igor in the commends on the op, was too manually add a link to the lib. In code blocks, this is accomplished by going to project --> Build Options, click the linker tab, and then manually browse to the file and include it. This has now made my project compile. Why code blocks requires this I don't know. But it does, so thanks Igor.