Suspending system using c++ program - c++

I am trying to suspend my system using a c++ program using SetSuspendState method but I am facing issue during linking.
I am using g++-4 (GCC) 4.3.4 20090804 (release) 1 compiler on Windows 7 OS (64bit).
The code I have written is
#include <iostream>
#include "windows.h"
#include "powrprof.h"
using namespace std;
int main() {
cout << SetSuspendState(false, true, false);
return 0;
}
Following is the error I am facing:
/cygdrive/c/Users/Vikas/AppData/Local/Temp/ccFpLgPi.o:suspend.cpp:(.text+0xa4):
undefined reference to
`_SetSuspendState#12' collect2: ld
returned 1 exit status
Kindly help me in resolving this issue.
Thanks in advance ...

I believe dlltool can be used to create import libraries from DLLs for use with GCC under Cygwin. The DLL exporting the functions pwrprof.dll should be located in your Windows system directory somewhere.

As msdn says you need to link PowrProf.lib.

Related

"undefined reference to `vkCreateInstance#12'" error when compiling C++ using Vulkan

I am trying to learn C++ and Vulkan while using windows 10. I have created a small program that I am compling with minGW. However when I add vkCreateInstance(&instanceinfo, nullptr, &myvulkaninstance) i get an error:
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\%USERNAME%\AppData\Local\Temp\ccDoOvlg.o:Renderer.cpp:(.text+0x5b): undefined reference to 'vkCreateInstance#12'
collect2.exe: error: ld returned 1 exit status
I get the above error in the 'Renderer.cpp' in the 'InitializeInstance' method (code can be seen below).
To compile my project I use this line in CMD g++ -L "C:/VulkanSDK/1.2.154.1/Lib/vulkan-1.lib" main.cpp Renderer.h Renderer.cpp -o build.exe. I do not know if I am compiling the library for Vulkan correctly as I was unable to find any good documentation about that online.
main.cpp
#include <iostream>
#include "Renderer.h"
using namespace std;
int main() {
Renderer renderer;
return 0;
}
Renderer.cpp
#include <iostream>
#include <cstdlib>
#include "Renderer.h"
// I again don't know if this is the right way to include this header
#include "C:/VulkanSDK/1.2.154.1/Include/vulkan/vulkan.h"
using namespace std;
Renderer::Renderer(){
}
void Renderer::InitializeInstance(){
VkInstanceCreateInfo instanceCreateInfo {};
instanceCreateInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
// This is the line where i get the error
auto error = vkCreateInstance(&instanceCreateInfo, nullptr, &vulkanInstance); // <--
if(VK_SUCCESS != error){
std::exit(-1);
}
}
Renderer::~Renderer(){
}
I have been using OpenGL and java (using LWJGL) for a while but now I wanted to learn Vulkan and C++. I am however still learning so I don't know a lot about any of these subjects. If you know how I could improve my compiling and/or prevent this error, please let me know.
Is your operating system 64-bit? If it is, please download MSYS2 and uninstall 32-bit MinGW. In MSYS2, use clang64 toolchain to compile your code again. It's not recommended to use 32-bit compilers with Vulkan SDK.

Trying to use Boost library on Codeblocks gives an undefined reference

I'm trying to use the boost library on CodeBlocks, but I'm new to it and I can't seem to be able to link it properly.
The boost folder(version 1.70) is in the same folder of my main.cpp, and the library I'm trying to access is libboost_filesystem-mgw92-mt-x64-1_70.a;
Here is my code:
#include <iostream>
#include <boost/filesystem.hpp>
int main()
{
boost::filesystem::path l_path("C:\\Hello.txt");
if(boost::filesystem::exists(l_path))
{
std::cout<<"exists!"<<std::endl;
}
else
{
std::cout<<"no";
}
return 0;
}
And some screenshots of my settings and of the error
Thank you!
Undefined reference to _Unwind_Resume suggests that you build Boost with different compiler than your project or you choose different type of exception handling.
Check if you're using the same compiler in both cases.
It might be also caused by building your project using gcc instead of g++. You should check that as well. In this case switch to g++ or explicitly link against libstdc++, by adding -lstdc++ to compiler flags.

Compiling boost::asio example on Windows

I am trying to switch to Windows environment from Linux, but find it a very hard path.
This time I wanted to test if I can work with boost library.
I had problems with compiling boost on windows, so I downloaded precompiled version. I unpacked everything and tested positively that I can compile the header-only librariers.
Then I copied some simple boost::asio example. I set up everything in Eclipse. Compilation went fine, but during linking I got 'undefined reference' problem to 'boost::system' internal stuff.
C:/Users/jacek/cpp/boost_1_62_0/boost/system/error_code.hpp:221: undefined reference to `boost::system::generic_category()'
C:/Users/jacek/cpp/boost_1_62_0/boost/system/error_code.hpp:222: undefined reference to `boost::system::generic_category()'
C:/Users/jacek/cpp/boost_1_62_0/boost/system/error_code.hpp:223: undefined reference to `boost::system::system_category()'
So I added '-lboost_system', as well as the path to the libraries directory, to my linking options. But this did not help.
g++ "-LC:\\Users\\jacek\\cpp\\boost_1_62_0\\lib64-msvc-14.0" -o TestAsio.exe "src\\Main.o" -lboost_system
I checked the libraries directory and found there is a bunch of files containing 'boost_system' in the name. They are:
libboost_system-vc140-mt-1_62.lib
libboost_system-vc140-mt-gd-1_62.lib
libboost_system-vc140-mt-s-1_62.lib
libboost_system-vc140-mt-sgd-1_62.lib
libboost_system-vc140-s-1_62.lib
libboost_system-vc140-sgd-1_62.lib
I did not know which I should use. I tried adding 'libboost_system-vc140-mt-1_62' to the linking options, I tried all other files, I tried renaming the files to the linux pattern 'libboost_system.a', but nothing worked.
g++ "-LC:\\Users\\jacek\\cpp\\boost_1_62_0\\lib64-msvc-14.0" -o TestAsio.exe "src\\Main.o" -llibboost_system-vc140-mt-1_62 -llibboost_system-vc140-mt-gd-1_62 -llibboost_system-vc140-mt-s-1_62 -llibboost_system-vc140-mt-sgd-1_62 -llibboost_system-vc140-s-1_62 -llibboost_system-vc140-sgd-1_62
What am I doing wrong here?
Please help...
YotKay
I solved it myself with the help of a comment from this post: boost asio example compilation error
It looks like the precompiled version of Boost is created with Visual Studion and is NOT COMPATIBLE with G++. I if I decided to install MinGW then I cannot use the precompiled version of boost, but must compile it myself using g++.
I did that.
Now I have libraries compiled with G++.
I specify the path to the boost system library like that:
c:\Users\jacek\cpp\boost_1_62_0\libraries\boost\bin.v2\libs\system\build\gcc-mingw-6.2.0\debug\link-static\
and add this option:
-lboost_system-mgw62-d-1_62
Now the problem with boost::system disappears. However, another one pops up with boost asio, but luckily the answer is here: MinGW linker error: winsock
The example works fine now on my Windows 10 laptop.
#include <boost/asio/io_service.hpp>
#include <boost/asio/steady_timer.hpp>
#include <chrono>
#include <iostream>
using namespace boost::asio;
int main()
{
io_service ioservice;
steady_timer timer{ioservice, std::chrono::seconds{3}};
timer.async_wait([](const boost::system::error_code &ec)
{ std::cout << "3 sec\n"; });
ioservice.run();
}

Trying to install and use LAPACK++, problems with loading shared libraries

I am new to using libraries and I am having some trouble with lapack++ and getting it to work. I will explain what I have done and tried so far.
First I installed BLAS and LAPACK and that went fine. I now have installed LAPACK++ version 2.5.2 (http://lapackpp.sourceforge.net/) so I can call various linear algebra routines in C/C++. After I configure, make and then make install it places all the C/C++ header files in /usr/local/include/lapackpp/ some of which are..
arch.h
bmd.h
gmf.h
lapackc.h
lautil.h
spdmd.h
ultgmd.h
bfd.h
...
and also the following files in /usr/local/lib
liblapackpp.la
liblapackpp.so
liblapackpp.so.14
liblapackpp.so.14.2.0
Now if I try to compile using g++ the simple code of
#include <lapackpp/lapackpp.h>
using namespace std;
int main(int argc, char** argv) {
return 0;
}
I get the following output...
In file included from /usr/local/include/lapackpp/lapackc.h:14,
from /usr/local/include/lapackpp/lapack.h:10,
from /usr/local/include/lapackpp/lapackpp.h:16,
from test.cpp:1:
/usr/local/include/lapackpp/lacomplex.h:45:23: error: laversion.h: No such file or directory
/usr/local/include/lapackpp/lacomplex.h:48:17: error: f2c.h: No such file or directory
In file included from /usr/local/include/lapackpp/lapackpp.h:47,
from test.cpp:1:
/usr/local/include/lapackpp/latmpl.h:36:22: error: lafnames.h: No such file or directory
I solved this problem by writing the location of the header file explicitly in the header file that was causing trouble.
Eg. I replaced
#include
with
#include
After doing this my code compiles fine.
Now if I try to compile the code
#include <cstdlib>
#include <iostream>
#include <lapackpp/lapackpp.h>
using namespace std;
int main(int argc, char** argv) {
LaGenMatDouble A(5,5);
cout << "This is a test." << endl;
return 0;
}
by typing
g++ test.cpp -o test -I usr/local/include/lapackpp
I get the following errors
/tmp/ccAq6nkP.o: In function `main':
test.cpp:(.text+0x22): undefined reference to `LaGenMatDouble::LaGenMatDouble(int, int)'
test.cpp:(.text+0x4f): undefined reference to `LaGenMatDouble::~LaGenMatDouble()'
test.cpp:(.text+0x67): undefined reference to `LaGenMatDouble::~LaGenMatDouble()'
collect2: ld returned 1 exit status
(Info on LaGenMatDouble is here )
which suggests I may be linking to the library wrong?
After some googling I realised that I needed to link to the header files using -I and the shared library by -L and the library itself by -llapackpp, so then I typed
g++ test.cpp -o test -I usr/local/include/lapackpp -L usr/local/lib -llapackpp
which compiled the code, now when I ran the program by typing ./test I go the error
./test: error while loading shared libraries: liblapackpp.so.14: cannot open shared object file: No such file or directory
and now I am confused.
I am unsure if this has anything to do with the problem but when I type
pkg-config lapackpp --libs
I get
Package lapackpp was not found in the pkg-config search path.
Perhaps you should add the directory containing `lapackpp.pc'
to the PKG_CONFIG_PATH environment variable
No package 'lapackpp' found
The same happens for lapack and blas too.
I am unsure what to do. Any help would be very much appreciated, thanks!
Linking goes fine because you tell to the linker where the library is, but execution failed because the loader doesn't know anything about the location of your libraries (you can check that performing ldd yourapp, which shows the library needed by your application).
Usually, you can solve that by telling to the loader where the library is through the variable LD_LIBRARY_PATH, but it is a crude tool. A different solution is to encode that instruction directly in the executable, as described here, or simply to link statically your application using the switch -static
If you're after a C++ library that wraps LAPACK (and/or BLAS), you might be better off using a more modern library such as Armadillo. Besides using LAPACK as a backend for solvers and matrix factorizations, it uses expression templates to speed up operations.

How to get Xlib code work in eclipse for C++ ubuntu

I have some code with the following headers for Xlib but don't know what to do to make it work...I can't find these headers.
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xos.h>
#include <X11/Xatom.h>
Sorry new to this..
Okay so now I can view the headers in the foldrrs in my eclipse IDE.
and i get the following errors.Thee is no problem with the source as friends have run it from the terminal,and i want to do it from eclipse ide:
In function main':
/home/abbas/workspace/test3/Debug/../src/test3.cpp:51: undefined reference toXOpenDisplay'
and many other errors of the same type but the functions are different.
collect2: ld returned 1 exit status
make: *** [test3] Error 1
Plzz hellpp!!
Right click on Project Folder> Properties> C/C++ Build > Settings > GCC C++ Linker > Libraries > add "X11"