Codeblocks: Including library - c++11

I am trying to get started with the VJoy virtual joystick, but i am having trouble getting it up and running.
I keep getting this error:
main.cpp|14| undefined reference to `_imp__vJoyEnabled'
I am trying to get it running using the code below.
#include <iostream>
#include <windows.h>
#include <stdlib.h>
#include "public.h"
#include "vjoyinterface.h"
using namespace std;
int main()
{
// Get the driver attributes (Vendor ID, Product ID, Version Number)
if (!vJoyEnabled())
{
cout << "Function vJoyEnabled Failed - make sure that vJoy is installed and enabled\n" << endl;
}
cout << "Hello world!" << endl;
return 0;
}
Within Codeblocks i have set the compiler to compile with C++11.
Also within Codeblocks i have linked the library (Project build options -> linker settings -> add library)
I have also tried playing with the Search Directory, but i can't seem to get it working.
Any ideas what i am missing?

I found out i was linking to the wrong locations. Unfortunately there wasn't a clear error indicating this.
So the solution to this problem(in my case):
-Make sure you link to the right library locations
-Move the libraries and all of its associated files inside of the codeblocks project folder
-Add the library to the linked libraries(Project build options -> Linker settings -> Link libraries)
-Add the library locations to the search directories(Project build options -> Search directories -> Linker -> add)

Related

Recursive include of files in OpenCL source under Xcode

I'm looking to build a host program calling OpenCL code running on my GPU device. The cl source has the following form:
#include "skip_mwc.cl"
typedef struct{ uint x; uint c; } mwc64x_state_t;
//blah...
If I get rid of the #include directive and copy/paste the content of "skip_mwc.cl" directly into this source, I can partially "build" and at least get some errors, showing that my compiler (clang9 cl compiler) can at least recognize the kernels code. With the #include approach I get the following error:
Build log::
<program source>:9:10: fatal error: 'skip_mwc.cl' file not found
#include "skip_mwc.cl"
I have checked and the file is there in the search paths, so I'm inclined to believe that my Xcode IDE doesn't index .cl files properly to perform automatic file inclusion (as in .c or .cpp).
I really want to avoid having to copy/paste source from one file into the other. Any suggestions from someone familiar with Xcode, who has encountered this problem and managed to solve it, are very welcome and needed.
Thanks,
A
Two possible solutions:
Set the -I include_dir compiler option in clBuildProgram(), see also this answer.
Read both files from C++ with fstream and string-concatenate their content.
Also see the option of embedding the OpenCL code into the executable via stringification macro.

Unable to link the 64bit ftd2xx static library with project dispaying linker error. How to link the ftd2xx 64bit library to the code

I'm trying to link the ftd2xx.lib (amd64 https://www.ftdichip.com/Drivers/CDM/CDM%20v2.12.28%20WHQL%20Certified.zip) static file to my test program in codeblocks. I'm running codeblocks(mingw) on a intel i3-7020, x64 based processor. I'm getting the linker error obj\Debug\main.o:main.cpp|| undefined reference to `_imp__FT_ListDevices#12'. Can someone please tell me how to link the static library of ftd2xx.lib 64bit version in codeblocks.
#include <iostream>
#include "ftd2xx.h"
using namespace std;
int main()
{
FT_STATUS ftStatus;
int numDevs;
ftStatus = FT_ListDevices(&numDevs,NULL,FT_LIST_NUMBER_ONLY);
cout<<numDevs<<endl;
return 0;
}
It is supposed to compile successfully and display the number of devices connected.

AVX Command Error for integer addition [duplicate]

Im learning to use intrinsics instead of asm-inlining. Yesterday, they were working but I always get error today. Changed nothing.
#include <iostream>
#include <intrin.h> // immintrin.h, smmintrin.h ... tried all, never worked
using namespace std;
int main()
{
_m256_zeroupper(); // __mm256_zeroupper(); does not work too
_mm128 x; // __mm128 x; does not work too
_mm256 y; // __mm256 y; does not work too
_m256_zeroupper(); // __mm256_zeroupper(); does not work too
cout << "Hello world!" << endl;
return 0;
}
Here are the errors. I tried all header files for different intrinsics but errors were same. Also reinstalled gcc but did not work.
Where am I wrong? What do I need to add to actually declare these intrinsic variables and functions?
C:\indirmeDenemesi\hello_intrin\main.cpp||In function 'int main()':|
C:\indirmeDenemesi\hello_intrin\main.cpp|8|error: '_mm256_zeroupper' was not declared in this scope|
C:\indirmeDenemesi\hello_intrin\main.cpp|9|error: '_mm128' was not declared in this scope|
C:\indirmeDenemesi\hello_intrin\main.cpp|9|error: expected ';' before 'x'|
C:\indirmeDenemesi\hello_intrin\main.cpp|10|error: '_mm256' was not declared in this scope|
C:\indirmeDenemesi\hello_intrin\main.cpp|10|error: expected ';' before 'y'|
||=== Build finished: 5 errors, 0 warnings (0 minutes, 0 seconds) ===|
Using 64-bit latest version of gcc on 64bit cpu with 64 bit windows.
CPU is FX8150.
Tried -march=bdver1 -mtune=bdver1 and it produced hundreds of junk error.
Does all these mean my CPU is dying?
Edit: some other projects are working now, but I did not change anything. This must be a project-specific thing.
Using code::blocks and when I right-click on a header and select "open", it gives error "could not find" but does not give any error when compiling related to that, just error for intrinsinc commands. Same for working projects(they compile everything and work, but does not find header files when right click and click open). Maybe some other windows services were interfering? I dont know but compiler errors are vanishing and coming again, time to time. Reinstalling also codeblocks did not solve. Only some projects can use intrinsics while other projects cannot(even if all projects have same headers.)
This code below does not work too.
#include <iostream>
#include <immintrin.h>
using namespace std;
int main()
{
_m256_zeroupper();
__mm128 x;
__mm256 y;
_m256_zeroupper();
cout << "Hello world!" << endl;
return 0;
}
Three things should make your code work:
Make sure you're using the -mavx compile flag.
Your variable should be declared as __m256 not _mm256.
Make sure you're including immintrin.h

In VS2010 ,VC++ error LNK 2019 with CoolProp 5.0.0

I am an amateur VC++ developer.
I want to use CoolProp (http://www.coolprop.org/) in my academic VC++ project as a static library in a win 32 app using a VS2010 Ultimate running in x64 laptop machine.
So i have downloaded ,
1.CoolProp.lib from http://sourceforge.net/projects/coolprop/files/CoolProp/5.0.2/static_library/
2.CoolProp.h from http://sourceforge.net/projects/coolprop/files/CoolProp/5.0.0/shared_library/
and placed both in a system folder.
Next i created a sample win32 console application in VS2010 as empty sln.
Added CoolProp.h as an Additional Include Directories in Properties->C/C++->General(Also copied all the dependent header files)
Added CoolProp.lib as an Additional Dependencies in Properties->Linker->Input->Additional Dependencies
Then i copied this program from http://www.coolprop.org/coolprop/HighLevelAPI.html#high-level-api
#include "CoolProp.h"
#include <iostream>
using namespace CoolProp;
int main()
{
// First type (slowest, due to most string processing, exposed in DLL)
std::cout << PropsSI("Dmolar","T",298,"P",1e5,"Propane[0.5]&Ethane[0.5]") << std::endl; // Default backend is HEOS
std::cout << PropsSI("Dmolar","T",298,"P",1e5,"HEOS::Propane[0.5]&Ethane[0.5]") << std::endl;
std::cout << PropsSI("Dmolar","T",298,"P",1e5,"REFPROP::Propane[0.5]&Ethane[0.5]") << std::endl;
std::vector<double> z(2,0.5);
// Second type (C++ only, a bit faster)
std::cout << PropsSI("Dmolar","T",298,"P",1e5,"Propane&Ethane", z) << std::endl;
std::cout << PropsSI("Dmolar","T",298,"P",1e5,"HEOS::Propane&Ethane", z) << std::endl;
std::cout << PropsSI("Dmolar","T",298,"P",1e5,"REFPROP::Propane&Ethane", z) << std::endl;
return EXIT_SUCCESS;
}
and tried to build.
Build(but compiled perfectly) failed due to
main.obj : error LNK2019: unresolved external symbol "double __cdecl PropsSI(char,char,double,char,double,char *)" (?Props##YANDDNDNPAD#Z) referenced in function _main
Can somebody please help me in resolving this ?
I already read below posts from stackoverflow , but couldnt solve please help
What is an undefined reference/unresolved external symbol error and how do I fix it?
"error LNK2019: unresolved external symbol" error in Visual Studio 2010
Error LNK2019: Unresolved External Symbol in Visual Studio
It is working for me, (VS 2010) as following:
-add file 'CoolPropLib.h' to your project, by right click on header files folder in solution explorer -> Add -> Existing Item -> choose 'CoolPropLib.h'.
-open file 'CoolPropLib.h' and comment line 22 as follow (//#include "PlatformDetermination.h").
- add these two lines (23, 24) :
#define CONVENTION __stdcall
#define EXTERNC
-use library that is built with __stcall not that built with __cdecel : http://sourceforge.net/projects/coolprop/files/CoolProp/5.0.0/shared_library/Windows/32bit__stdcall_calling_convention/CoolProp.lib/download
-you will need the dll (for __stdcall) from : http://sourceforge.net/projects/coolprop/files/CoolProp/5.0.0/shared_library/Windows/32bit__stdcall_calling_convention/CoolProp.dll/download
-create folder named 'lib' in your project folder in windows explorer (not in VS) and put 'CoolProp.lib' in it.
-in Properties->Linker->General-> Additional libraries Directories, add $(ProjectDir)\lib
-the code I test is:
#include "stdafx.h"
#include <iostream>
#include <vector>
#include "CoolPropLib.h"
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
// First type (slowest, due to most string processing, exposed in DLL)
std::cout << PropsSI("Dmolar","T",298,"P",1e5,"Propane[0.5]&Ethane[0.5]") << std::endl; // Default backend is HEOS
std::cout << PropsSI("Dmolar","T",298,"P",1e5,"HEOS::Propane[0.5]&Ethane[0.5]") << std::endl;
std::cout << PropsSI("Dmolar","T",298,"P",1e5,"REFPROP::Propane[0.5]&Ethane[0.5]") << std::endl;
return 0;
}
-if you have problems, I can upload the project to you.
EDIT 1:
I mean 'CoolPropLib.h' not 'CoolProp.h', I correct it; In your question, you named it as 'CoolProp.h'.
As you mentioned in your comment; you can change calling convention as _stdcall in Properties->c/c++ ->Advanced .
I am one of the the primary developers for CoolProp. Thank you #houssam for your helpful reply. The problem with going the DLL (shared library) route is that you lose access to a lot of useful low-level functions, whereas if you link with the static library, you still have access to all the low-level code
The better plan is to build the static library yourself, as it is required that the compiler that is used to build the static library is EXACTLY the same as the compiler used to compile your project. In order to do that, you can follow the directions here: http://www.coolprop.dreamhosters.com:8010/sphinx/coolprop/wrappers/StaticLibrary/index.html#static-library , basically you need to do
# Check out the sources for CoolProp
git clone https://github.com/CoolProp/CoolProp --recursive
# Move into the folder you just created
cd CoolProp
# Make a build folder
mkdir build && cd build
# Build the makefile using CMake
cmake .. -DCOOLPROP_STATIC_LIBRARY=ON -G "Visual Studio 10 2010"
# Make the static library
cmake --build .
You then need to link the static library as described by #houssam. No other changes should be required to your code.
In the future, the coolprop-users#googlegroups.com mailing list or https://github.com/CoolProp/CoolProp/issues are good places to ask questions.

Error 3 error LNK1104: cannot open file 'gtk-3.lib'

I have been trying to get GTK 3.0 to work, and have followed all the steps here
How to configure gtk on Visual studio 2010
And changing to 3.0 where needed to get GTK to work, and it seems to have loaded everything it needs in order to compile, but it gives me the error
Error 3 error LNK1104: cannot open file 'gtk-3.lib'
Whenever I try to run the program.
I am using visual studios 2012, but this was the only place i found anything about getting GTK to run on any visual studios.
Here is the code I am using:
#include <gtk-3.0\gtk\gtk.h>
int main(int argc, char* argv[])
{
gtk_init(&argc, &argv);
GtkWidget* window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
//gtk_widget_get_preferred_size(window, 300, 200);
g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL);
gtk_window_set_title(GTK_WINDOW(window), "GTK+ with VS2010");
gtk_widget_show(window);
gtk_main();
return 0;
}
I commented out the gtk_widget_get_prefered_size call because it is irrelevant to the problem
any suggestions? I've looked in several places but none came up with clear answers.
The library gtk-3.lib does not exist. In fact, the library reference is not required to build your GTK 3 application. The pkg-config helper doesn't seem to generate the correct linker flags needed to link your application.
Just add in your Additional Options area all the existing libraries found in your GTK package (\gtk3\lib). The lib files for my bundle (gtk+-bundle_3.6.4-20130921) were as follows:
atk-1.0.lib cairo.lib fontconfig.lib gailutil.lib gdk-win32-3.0.lib gdk_pixbuf-2.0.lib gio-2.0.lib glib-2.0.lib gmodule-2.0.lib gobject-2.0.lib gthread-2.0.lib gtk-win32-3.0.lib pango-1.0.lib pangocairo-1.0.lib pangoft2-1.0.lib pangowin32-1.0.lib
(or you can go to your library path via a command prompt and enter dir *.lib /B)
Don't forget to include the /ENTRY:mainCRTStartup flag mention in the initial answer you started with.
you may have to edit your project settings or use a pragma comment to link with your gtk library:
#pragma comment(lib, "gtk-3")//if the libray is on your project's path
#define PATH "C:\\example\\"
#pragma comment(lib, PATH"gtk-3")//if the library is on PATH

Resources