Link Errors w/ SFML 2.4 (C++) - c++

For a while now, I have been trying to use the SFML library for C++.
However, whenever I try to run my program, I get a slew of build errors revolving around undefined symbols. I am building from Visual Studio and I have added the include directory, the additional libraries, and the all the DLLs in bin into BOTH the source directory and the build directory. Still, I cannot get the program to build.
My Code:
#include <SFML\Graphics.hpp>
int main() {
sf::RenderWindow window(sf::VideoMode(640, 380), "Test Window");
while (window.isOpen()) {
// events
window.clear();
// drawing
}
system("pause");
}
Errors:
Include Directories: SFML-2.4.2/include
Lib Directories: SFML-2.4.2/lib
Linker Input:
sfml-main-d.lib
sfml-graphics-d.lib
sfml-window-d.lib
sfml-system-d.lib
sfml-audio-d.lib
sfml-network-d.lib

I know this is like one and a half year old but I had the same errors and I have resolved them.
The following Pastebin files are my config and task files which(in my case work fine with Visual Studio Code Version 1.32.3 read the bottom for what you will have to change)
Date:2019-03-14
Electron:3.1.6
Chrome:66.0.3359.181
Node.js:10.2.0
V8:6.6.345.32
Os: Windows_NT x64 10.0.17134
c_cpp_properties.json: https://pastebin.com/3gw8J4d2``
task.json: https://pastebin.com/s1rjswWG``
IMPORTANT:
change the following:
(If you have MinGW installed on the standard path)
c_cpp_properties.json: K:/libs/SFML-2.5.1/include has to be changed
to your installation path of SFML be sure to change it in the browse path too!!!
tasks.json:
"-IK:/libs/SFML-2.5.1/", change K:/libs/SFML-2.5.1/include to your
installation path of SFML
"-LK:/libs/SFML-2.5.1/lib", change K:/libs/SFML-2.5.1/lib again to
your installation path of SFML
a few mistakes I made:
I didn't delete the K: in "-LK:/libs/SFML-2.5.1/lib"
I didn't have g++ in command at the top of tasks.json
I didn't use the right compiling/link paths (search for all paths you
use in your browser before giving up)
A few helpful Links:
https://www.sfml-dev.org/download/sfml/2.5.1/ (for MinGW be sure to
select GCC 7.3.0 MinGW (DW2) - 32-bit)
https://code.visualstudio.com/docs/languages/cpp (Documentation on
how to compile in Vs with c++)
https://discordapp.com/invite/nr4X7Fh (Discord Server of SFML where
are a lot of helpful people for the library)
I hope I helped
If you have any question you can message me on Reddit u/Spagetti_Lord (most active)

Related

compiling CGAL draw_polygon and linking qt5

I am trying to learn meshing algorithm for CFD puposes and I found CGAL to be a good library to learn everything from ground. My vcpkg cgal[qt5] installation failes due to some problem in installing boost. But other library installation works. I also tried to follow this tutorial but OpenGR and libpointmatcher library generation fails and results cmake error. So I have to setup everything manually. I am using Visual Studio 2022 and Qt5.15.2. I have qt extension downloaded and configured in visual studio. I have also QTDIR variable created in enviroment variables and Qt bin directory in system path.
What I did is as follows-
(1). first I created an empty console application called polygon and added various example code provided by cgal as a source and configuration x64, Release. changed
(2). created a folder library inside solution directory and extracted downloaded cgal-5.5.zip(has include, data, demo, etc ....) to library directory and added $(SolutionDir)library\cgal-5.5\include to additional include path in property manager.
(3). downloaded boost_1_80 from boost.org and compiled with the foolowing steps-
.\bootstrap
open project-config.jam and add-
using mpi ;
using python ;
run the command-
.\b2 --build-dir=build\x64 address-model=64 threading=multi --stagedir=stage/x64 --toolset=msvc -j 16 link=static,shared runtime-link=static,shared --variant=debug,release
added the boost_1_80 folder in include path and stage/x64/lib to additional library directory.
(4). I have built gmp and mpfr with vcpkg with .\vcpkg install gmp:x64-windows-static & .\vcpkg install mpfr:x64-windows-staticcommand and copied the folders gmp_x64-windows-static and mpfr_x64-windows-static to the library directory. I added include and lib folder of both library to respective path and in linker->additional dependency included the two lib file gmp.lib and mpfr.lib
(5). copied images, meshes, points_3 folder from data to solution directory
I can add eigen3, zlib to my project using the same process and all the examples I tried depend on the above libraries compiled and ran properly.
The problem comes when I try to do examples involves qt5. For example program draw_polygon.c-
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Polygon_2.h>
#include <CGAL/draw_polygon_2.h>
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Polygon_2<K> Polygon_2;
typedef CGAL::Point_2<K> Point;
int main()
{
// create a polygon and put some points in it
Polygon_2 p;
p.push_back(Point(0,0));
p.push_back(Point(4,0));
p.push_back(Point(4,4));
p.push_back(Point(2,2));
p.push_back(Point(0,4));
CGAL::draw(p);
return EXIT_SUCCESS;
}
I tried following this tutorial but it's made for older version of Qt(Qt4) and Qt5 does not have Qt folder(..\path to\Qt<QT-version>\include) inside includes. This program does not any form file but I added the rest of the includes and lib files accordingly. When I try to compile, it says CGAL_USE_BASIC_VIEWER not defined. Given in this article if I write #define CGAL_USE_BASIC_VIEWER before the includes the generated are like -
Then I tried doing from qt empty project in visual studio interface which still gives -
Obviously my linking failed. How do I fix it for my case? I have went through several other articles none had definite answers.

Can't build C++ project with XLNT library

I am trying to build a sample project using the XLNT-Library under Windows 8 using MinGW g++.
The code is the sample code found in the github Documentation:
#include <xlnt/xlnt.hpp>
int main()
{
xlnt::workbook wb;
xlnt::worksheet ws = wb.active_sheet();
ws.cell("A1").value(5);
ws.cell("B2").value("string data");
ws.cell("C3").formula("=RAND()");
ws.merge_cells("C3:C4");
ws.freeze_panes("B2");
wb.save("example.xlsx");
return 0;
}
I downloaded the library as a zip file, extracted it and copied the folder [xlnt-master-root]\include\xlnt into the folder where my main.cpp resides and then tried to compile it with this command:
g++ -std=c++14 -lxlnt -Ixlnt/include .\excelTest.cpp -o excelTest.exe
But this results in the following error:
c:/users/s/documents/myprogramms/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe:
cannot find -lxlnt
I also tried copying the [xlnt-master] folder to the main.cpp location and tried to compile it again with the same result.
I can program in C++ but I have not worked with libraries before.
Can you please give me a hint how to use and compile the project with the library correctly?
FYI: I also tried building the library with with cmake as found here.
Although cmake was a success, make -j8 won't do anything because no Makefile is created in the build directory.
Maybe I went wrong here?
Thanks for your help...
using the lasted visual studio 2017,you can build the xlnt library automatic.
you can download the library below:
https://1drv.ms/f/s!AvyYANq3dYDem1g9MtINWWw7CyTH

Qt not working with VTK libraries

Hi stackoverflow family
I'm trying to get vtk working with qt. I should admit that I'm a newbie, so go easy. I'm trying to learn c++ for myself and have chosen the following configuration to get me started;
OS: Windows 7 ultimate
toolkit: QT 5.3.2
IDE: QT Creator 3.2.1
VTK: 6.3.0
I downloaded and extracted the VTK to "C:\vtk-6.3.0" on my computer. I followed the instructions given on VTK's website to build VTK with cmake. I gave cmake the location of the source "C:/vtk-6.3.0" and specified a place to build the libraries "C:/vtk/bin".
Thinking everything had gone smoothly, I proceeded with the simplest example I could get away with, an example without a ui. I got the example from here
RenderWindowNoUiFile.cxx
#include <QApplication>
#include <vtkSmartPointer.h>
#include <vtkSphereSource.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <QVTKWidget.h>
int main(int argc, char** argv)
{
QApplication app(argc, argv);
QVTKWidget widget;
widget.resize( 256, 256 );
vtkSmartPointer<vtkSphereSource> sphereSource =
vtkSmartPointer<vtkSphereSource>::New();
vtkSmartPointer<vtkPolyDataMapper> sphereMapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
sphereMapper->SetInputConnection( sphereSource->GetOutputPort() );
vtkSmartPointer<vtkActor> sphereActor =
vtkSmartPointer<vtkActor>::New();
sphereActor->SetMapper( sphereMapper );
vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
renderer->AddActor( sphereActor );
widget.GetRenderWindow()->AddRenderer( renderer );
widget.show();
app.exec();
return EXIT_SUCCESS;
}
I added my .pro file manually
RenderWindowNoUiFile.pro
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = RenderWindowNoUiFile
TEMPLATE = app
SOURCES += RenderWindowNoUiFile.cxx
INCLUDEPATH += C:\VTK\bin
I observed that qt has underlined all of the header files and when I ran the program and I got the error
Projects\RenderWindowNoUiFile\RenderWindowNoUiFile.cxx:3: error: vtkSmartPointer.h: No such file or directory
#include <vtkSmartPointer.h>
^
Please what I'm I doing wrong?
When I searched for any of the header files, I find each in a different location in the "C:\vtk\bin" or "C:\vtk-6.3.0" folder.
Please how do I solve this problem? Can I get all of the header files in a single folder so that I can refer to it in the .pro file?
For example if I can get all the header files in a directory called "C:\vtk\header", then I can refer to it in my .pro file as INCLUDEPATH += C:\vtk\header
You kind of touched on it with your comment "can I get all the headers in one directory" That is the setting INCLUDEPATH, but you have it set incorrectly.
There are a few issues in what you are doing.
First, your INCLUDEPATH is incorrect. It should be set to the "include" directory of the files that you've installed.
Second, you haven't included the library in your build- so even if your include files resolved, you would get link errors. This is because you haven't specified where the binary library files are.
Third, you didn't specify if your VTK build was static or dynamic. I'll assume this is dynamic. IF you don't know what this means, please look that up. The big difference is: do you need to also copy a .dll file to where your program is running from. If you have dynamic, the answer is yes.
About the comment a out the install target: with cmake you can set an option to change where it installs the binaries to. So the process goes like this with cmake:
1) Get the sources unpacked to a directory that you like.
2) Run cmake build folder (which you set to bin). What you did was confusing, because the build folder will contain everything: not just binaries, but headers and other install stuff. I usually call it "build"
3) Once cmake configures it may prompt for more configuration. This is where you may want to configure Qt for VTK. In this step you tell cmake where the Qt cmake folders are, so that you can configure VTK to build Qt stuff
4) Now you can change the default install path. By default, when you build the INSTALL project with visual studio (I'll describe below) it installs somewhere in program files. You can change this by setting CMAKE_INSTALL_PREFIX to whatever you want. For example: C:\VTK\install
5) Click generate to generate the visual studio project files or Make files, depending on your build configuration.
6) For visual studio: open the solution in the build directory and build all. When this completes, to install the files (#4) run the INSTALL project.
7) For Make files: run make (if you have multiple cores, use -jX where X is twice number of cores) then make install (don't use -j with make install)
Ok at this point you've compiled and installed the VTK distribution. Now you should fix your paths in your Qt .pro file.
For example:
INSTALLPATH+=C:/VTK/install/include
I don't know which libs you need, but below you should see the pattern:
LIBS+=-LC:/VTK/install/lib \
-lvtkRenderingCore-6.3
Now after this, since you have a dynamic build you need to copy the .dll files next to the exe file that you are creating from your Qt project.
Good luck!
If you use mingw with qt ,you have to compile source of vtk with mingw as you know.In that web page they use vs so I want to warn you about it.When you configure vtk source with cmake you should check "Module_vtkGUISupportQt" and "Module_vtkGUISupportQtOpenGL" options to able to work with qt.Also you have to do some config in Run & Build Options in Qt such as selecting compiler, kits etc.
Notice that choosing a compiler which is released after the release date of the library(in this case vtk) may prevent you from suffering of much errors.

boost 1.53 python fatal error LNK1104 boost_python-vc110-mt-gd-1_53.lib

I'm trying (for a few days now) to build a DLL generated from C++ code with boost/python to be used by python. I am a Student from Germany and had mostly to do with Java until now (I wrote some basic OpenGL and gimp filter stuff before in C++). So pardon me in advance for bad english or C++ beginner mistakes. I mean, programming with Java really is a lot more comfortable in comparison to C++. But enough of the skirmish.
The error:
LINK : fatal error LNK1104: File "boost_python-vc110-mt-gd-1_53.lib" could not be openend
My presets:
-using MS Visual Studio 2012 (11.0)
-using boost_1_53_0
-using python2.7 (I heard 3.3 may cause some Problems)
What I did:
Installed python and added it to PATH. Then created a new empty project in VS and a class file "Test.cpp" with following content as described on the boost tutorial page:
char const* greet()
{
return "hello world";
}
#include <boost/python.hpp>
BOOST_PYTHON_MODULE(Test)
{
using namespace boost::python
def("greet", greet);
}
Then came the new part for me, in VS Project Properties:
Configuration Properties > General > Configurationtype > Dynamic Library (.dll)
C/C++ > General > Addition Includedirectories > C:[..]\boost_1_53_0
Linker > General > Additional Library Directories > C:[..]boost_1_53_0\stage\lib
From the error I am assuming i did something wrong with Linker or Include. I also changed the Linker > General > Additional Library Directories to boost_1_53_0\libs because i wasn't sure, but the same error occured. And yes, I correctly included python. I am also not sure if i have to put something else beside python into Linker > Input for boost.
Then I build boost with bjam with no options except msvc-11.0 to be sure to have everything i need (though I read that boost/python doesn't need an extra build) and still got the same error. Can someone help me? I would love to have a step by step description of what to do. I am really despairing of this.
Btw.: I had the same error as this guy a few days before Linker error LNK1104 with 'libboost_filesystem-vc100-mt-s-1_49.lib' then stopped working on it and as I started again I got my brand new error (I can't tell you how this happened).
Since it is looking for a static library, add BOOST_PYTHON_STATIC_LIB flag, go to VS properties -> Preprocessor -> Processor definition, add BOOST_PYTHON_STATIC_LIB flag.
You need to create a "user-config.jam" file that indicates where the python headers and libs can be found by Boost.Build. You can create it in your boost_1_53_0/ directory with the following contents:
# Configure specific Python version.
using python : 2.7
: C:/Python27/python.exe
: C:/Python27/include #directory that contains pyconfig.h
: C:/Python27/libs #directory that contains python27.lib
: <toolset>msvc ;
Then from that boost_1_53_0/ directory you need to invoke b2 like this in order to build the missing library:
b2 toolset=msvc-11.0 --with-python variant=debug runtime-debugging=on link=shared --user-config=user-config.jam stage
(although I would recommend b2 toolset=msvc-11.0 --with-python --user-config=user-config.jam --build-type=complete stage so you can get in one step all the configurations that you might need in the future)
Once you have the libraries you need to add the directories to Visual Studio ( both to boost and to python).
Once you have successfully built the module you need to rename it to Test.pyd (exact name you used in BOOST_PYTHON_MODULE. If you have the python and Boost.Python libraries in your PATH or in your current directory you will be able to use the script in the tutorial:
import Test
print Test.greet()
and get the familiar "hello world".
Note that I'm very thankful for your tries but none of your answers helped. A fellow student then gave the hint for the right answer to me and some steps are really easy, others I don't understand, but it works now.
First Problem was: The new boost 1.53.0 does not work with Python27 or older. I then linked it with Python33 and had the build error removed.
But of course the build version didn't work without an error. As I tried to start my helloboost.py which imports from the .pyd built by VisualStudio and invokes the greet method, the following error occured:
ImportError: DLL load failed: The specified module could not be found.
As i checked the hello_ext.pyd with the dependency walker and wildly copy pasted around, I found out it needs the boost_python-vc110-mt-gd-1_53.dll (probably depending on what you need and built with bjam before) in the same folder. It worked then. Maybe someone can explain why nowhere was explained that I need this dll in the same folder as the pyd (or did I miss something? Is it just because I made a mistake before?)
Anyhow, I'm very glad it works now and hope it helps other people.
You probably will have worked this out by now - however:
When a .exe looks for a .dll to load no path is specified. Therefore a .dll must be in the search path for the file.
Also: I was trying to build 1.49 libs for Visual Studio 2013 - and kept getting the LNK error from my project. I don't know who suggested it on stackoverflow but someone\something gave me the idea to copy build system from a more recent boost which knows how to make .libs for more recent environments. (thank you)
I had to copy the boost build system from a 1.58 after running bootstrap in 1.58, copy b2, bjam and boost-build.jam to the earlier boost folder root to replace the same named files there. Also you will need to copy the later tools\build folder to support the build system.
Noting here in the hope it might help someone else in a similar cituation I found myself in.
See: Search Path Used by Windows to Locate a DLL

CMake generated Xcode project fails to find the binary "Products" that are built from Xcode

I am trying to use CMake Generated Xcode project. Everything looks good when building, except that Xcode can not find the binaries that are built. Below is a screenshot i took after successfully build the product. I can see them in the project source directory. However, notice that the Xcode showing RED "HelloWorld", which means it can not find the products.
Configurations: CMake 2.8.6 with Xcode 4.2 on Lion 10.7.2
This is CMakeLists.txt
project(HelloWorld)
add_executable(${PROJECT_NAME} HelloWorld.cpp)
This is the source code for HelloWorld.cpp
#include <iostream>
int main(){
std::cout << "HelloWorld!" << std::endl;
return 0;
}
I tried to create a raw project directly from Xcode, after compiles, the products shows black instead of red font, which means Xcode found the products. So i am sure this is related to CMake Generated Xcode project.
Anyone got any idea? how to fix this?
The xcode project file (which I guess, in your case would be named something like HelloWorld.xcproject/project.pbxproject, will have SYMROOT definitions for each of the build configurations per target.
You can either change all the SYMROOT definitions to the same value or remove all of those (xcode will default to "build").
Project, if open, should autoreload. Select ALL_BUILD or HelloWord, clean and build.
Not sure if it is an issue with the way cmake adds the SYMROOT.
Note: I know this only hints at what the problem could be and not a solution but am not allowed to add comments yet :)
I had the same issue. For me it was caused by an extra "build" directory in the search path Xcode was using to find the product. I hacked around the problem by putting the products in the location Xcode expects, i.e. I added the extra "build" directory.:
if(CMAKE_GENERATOR STREQUAL Xcode)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/build/Debug)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/build/Release)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/build/Debug)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/build/Release)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/build/Debug)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/build/Release)
endif()