To the best of my knowledge, this isn't a duplicate of an existing question. This question is specifically about Visual Studio's auto-linking SDL2 libraries.
I've installed SDL2 (x64-windows variant) with vcpkg:
vcpkg install sdl2 --triplet x64-windows
And I've made vpkg libraries available to Visual Studio:
vcpkg integrate install
My VS 2019 project is configured to use the Console subsystem, and my main program looks like that:
#define SDL_MAIN_HANDLED
#include <SDL2/SDL.h>
int main(int, char*[])
{
}
Why do I need to specify SDL_MAIN_HANDLED? It seems that auto-linking with SDLmain2.lib doesn't happen for some reason?
If I don't specify SDL_MAIN_HANDLED, linking fails:
unresolved external symbol main referenced in function "int __cdecl invoke_main(void)" (?invoke_main##YAHXZ)
I've also tried adding extern "C" on main() declaration but to no avail.
I've written many apps with SDL2 but this is the first time I'm using vcpkg to locate it.
It appears to be a deliberate decision made by those who created the package.
If you look at the package description file, you can see that SDL2main.lib is being moved into the manual-link directory. I'm not familiar with vcpkg, so I don't know how exactly you can "manually link" against it, but I assume it's possible.
Linking SDL2 manual-link libraries while using vcpkg with VS
My answer is a follow-up to #HolyBlackCat, thanks for help.
In your case, the directory is x64-windows, by default it is x86-windows.
Right-click on your project -> Properties -> Configuration Properties
First step
Go to: VC++ Directories -> Library Directories
For Debug configuration, add:
$(VCPKG_ROOT)\installed\x64-windows\debug\lib\manual-link
For Release configuration, add:
$(VCPKG_ROOT)\installed\x64-windows\lib\manual-link
Second step
Go to: Linker -> Input -> Additional Dependencies
For Debug configuration, add:
SDL2maind.lib
For Release configuration, add:
SDL2main.lib
Now you should not be bother by "main() redefinition" errors.
Related
I have been trying to build a cmake c++ project. More specifically I am trying to use the gdal library in this project. In the CMakeLists.txt it says find_library(GDAL gdal) after doing some research i found, that visual studio can open cmake files by default as mention in this thread: https://learn.microsoft.com/en-us/cpp/build/cmake-projects-in-visual-studio?view=vs-2019.
Moreover, visual studio should also automatically include the gdal library once i have set it up with vcpkg correctly. I've already downloaded the x64-windows version of the library (vcpkg install gdal:x64-windows) in order to build for the right architecture and made it available via vcpkg integrate install on a user-wide scope.
After some trial and error, everything works fine now, the toolchain gets included accordingly and the library is found automatically, resulting in a configuration like that:
However, when trying to include the header files (or anything else; see code snippet), visual studio does not seem to link the library correctly as it will result in the error message: cannot open source file "gdal/gdal.h".
#include <gdal/ogrsf_frmts.h>
#include <gdal/gdal.h>
#include <gdal>
Where should I further investigate?
As others have said vcpkg integrate install and vcpkg.cmake don't work together the reason being:
set_target_properties(${name} PROPERTIES VS_USER_PROPS do_not_import_user.props)
set_target_properties(${name} PROPERTIES VS_GLOBAL_VcpkgEnabled false)
this deactivates the integration. The reason to deactivate the integration is so that you don't write an incomplete CMakeLists.txt (e.g. missing the include directory or not linking all required libraries).
As such replace find_library(GDAL gdal) with find_package(GDAL REQUIRED) and target_link_libraries against the target GDAL::GDAL (https://cmake.org/cmake/help/v3.17/module/FindGDAL.html)
I wanted to create new OpenGl/GLEW/GLFW Visual Studio project in 64 bit. So I downloaded glew binaries and glfw binaries. My project settings are as followed:
Additional Libraries:
glew-2.1.0\lib\Release\x64
glfw-3.3.bin.WIN64\lib-vc2019
Additional Dependencies:
glew32s.lib (I dont get why its named glew32 and its in x64 folder)
opengl32.lib
glfw3.lib
With such setting for every glew function like glGenBuffers or glUseProgram or anything I get LNK2001 unresolved external symbol error.
Any clue where I did a mistake?
(And since I am a new to all of these can someone explain why do I have to link opengl32.lib on 64 bit app and why there is no opengl64.lib and so on?)
When you want to link the static glew library on windows, then you've to define the GLEW_STATIC preprocessor definition when you compile your application.
See Building Your Project with GLEW
and GLEW - why should I define GLEW_STATIC?.
If you use gnu (g++), then just add -D GLEW_STATIC to the build command.
In Visual Studio add GLEW_STATIC to the Project properties -> C/C++ -> Preprocessor -> Preprocessor Definitions
Well it seems to work when I link it dynamicly (glew32.lib instead of glew32s.lib).
Still no clue why static linking didnt work out.
I am trying to build tensorflow as a standalone project and have been following this tutorial
http://www.stefanseibert.com/2017/10/tensorflow-as-dll-into-your-windows-c-project-with-gpu-support-and-cmake-v1-3/
but alternatively with cpu support
My environment setup versions
protobuf 3.6.1
tensorflow 1.10.0
tf.GIT_VERSION = b'v1.10.0-rc1-19-g656e7a2b34'
Here are the steps I used to generate the shared lib
Acquired source code from https://github.com/tensorflow/tensorflow.git
Have installed the dependencies since I do not use the python bindings, there is no need for SWIG, so I installed Git (version 2.15.1.windows.2) and cmake 3.11.1
I used the 64bit tools from Visual Studio 2015 since VS2015 is necessary to build the DLL. I should be able to open the “VS2015 x64 Native Tools Command Prompt”. This is needed so VS uses the 64 bit toolset.
Navigated in the commandline to the “tensorflow/contrib/cmake” subfolder of the source code and create a directory with “mkdir build”. Afterwards navigate to the fresh build folder with “cd build”.
Create a build solution: cmake .. -A x64 -DCMAKE_BUILD_TYPE=RelWithDebInfo -Dtensorflow_BUILD_CC_EXAMPLE=OFF -Dtensorflow_ENABLE_GRPC_SUPPORT=OFF -Dtensorflow_BUILD_CC_TESTS=OFF -Dtensorflow_BUILD_PYTHON_TESTS=OFF -Dtensorflow_ENABLE_GPU=OFF -Dtensorflow_WIN_CPU_SIMD_OPTIONS=/arch:AVX -Dtensorflow_BUILD_SHARED_LIB=ON
Everything went fine till this. To build the tensorflow.dll, I issued the following command: MSBuild /p:Configuration=RelWithDebInfo tensorflow.vcxproj
This throws an error: D:\work\tensorflow\tensorflow/core/lib/core/stringpiece.h(34): fatal error C1083: Cannot open include file: 'absl/strings/string_view.h': No such file or directory (
compiling source file D:\work\tensorflow\tensorflow\core\lib\core\coding.cc) [D:\work\tensorflow\tensorflow\contrib\cmake\build\tf_core_lib.vcxproj].
I fixed the above error with this: https://github.com/tensorflow/tensorflow/issues/22007#issuecomment-424553600.
Doing the above I ended up with this error: path.obj : error LNK2019: unresolved external symbol "void __cdecl absl::base_internal::ThrowStdOutOfRange(char const *)" (?ThrowStdOutOfRange#base_internal#absl##YA
XPEBD#Z) referenced in function "class std::basic_string,class std::allocator > __cdecl tensorflow::io::internal::JoinPathIm
I am not able to proceed further. Any workaround for this? Thanks!
lnk2019 error occurs when your directly you are using in your source code are not linked properly. Please add additional dependencies to your project.
Going to project properties
select C/C++ option
Add aditional dependencies
Go to Linker Option Below C/C++
Add additional Dependencies here.
It might be help full for you from getting out to LNK2019 problem
view this to understand LNK2019 error.
I met same issue, I think tensorflow new version doesn't support CMake, but we can solve the issues.
1. Seems the absl version in project folder is out dated, so I cloned the latest version of abseil-cpp from: https://github.com/abseil/abseil-cpp
2. Use cmake to build the abseil-cpp, it will be fast.
3. Add lib path to tensorflow dependency, the needed one will be D:\git\abseil-cpp\abseil-cpp\build\absl\base\Release\absl_absl_throw_delegate.lib
4. If you meet other linking error, you can find the function name in absl sources and find the library contain it.
Hope this can help you and people who may met this issue in future.
I created a project using freeglut and glew and am attempting to statically link them. Currently when I build the project, I get an exe and two dlls(freeglut32.dll and glew32.dll). I'd like to make it so that I only get the exe.
To install the libraries I used NuGet. (Install-Package freeglut) and (Install-Package glew). NuGet downloads glew.lib to .\packages\glew.1.9.0.1\build\native\lib\v110\x64\Release\static\glew.lib and freeglut to .\packages\freeglut.2.8.1.15\build\native\lib\v110\x64\Release\static\freeglut.lib.
I assume they are the .lib files I wanted because they are both over 1 MB.
In Visual Studio, I went to Linker -> Input -> Additional Dependencies and added the paths of freeglut.lib and glew.lib. I also added #define GLEW_STATIC and #define FREEGLUT_STATIC to my code. Link Library Dependencies is turned on.
Even still, building the project gives me my 654 KB exe along with 224 kb of freeglut.dll and 356 kb of glew32.dll.
How can I make sure it so that glew32.dll and freeglut.dll do not exist and I am just given the single executable?
Edit:
Due to suggestions:
I went to Properties -> Referenced Packages and set freeglut and glew to Static.
You need to build static libraries for glew and freeglut that are compatible with your project settings
Step 1) Download and build vcpkg.exe ( a open source auto packaging tools from Microsoft) and make sure to keep built settings similar to your current project. Later vcpkg will use these settings as the default or intrinsic values.
Step 2) Open PowerShell in administrative mode and go the vcpkg directory
Step 3) Type .\vcpkg install glew:x64-windows-static This tells the packager to build a static library of the project for x64 machine. Repeat for freeglut. Your static libraries are ready for manual linking. Under the vcpkg\ installed\x64-windows-static\ , you can find subdirectories viz lib ( your lib are here), and include directory contains your glew include files.
Step 4) [Optional] If you want to auto link the installed packages to your visual studio C++ projects (available in VS 2015 or later only), type
.\vcpkg integrate install
Many open source windows projects can be auto build using this tool, enjoy.
I'm trying to run some simple examples with Boost and I'm continuously running into this error and I have tried to compile this but I haven't been able to create "libboost_system-vc100-mt-gd-1_46_1.lib".
I keep ending up with this issue:
error LNK1104: cannot open file 'libboost_system-vc100-mt-gd-1_46_1.lib'
Anyone encounter this error before? How do you compile this properly with NMAKE because it keeps telling me it's bulding "boost.regex without ICU / Unicode Support" which is giving it a "fatal error U1073 and tells me it doesn't know how to make "../src/c_regex_traits.cpp".
Sorry if this is a jumble it's just a lot of information that's getting more and more confusing to me.
Your boost is not properly built or installed. Please follow the instruction on how to install boost.
You need to build the boost libraries first.
To do this, open command line & go to boost root eg C:\dev\boost\1_46_1.
Depending on whether you want to build for 64bit or 32bit applications, type
(x64):bjam toolset=msvc address-model=64 variant=debug,release link=static threading=multi runtime-link=static,shared stage
(x86): bjam toolset=msvc variant=debug,release link=static threading=multi runtime-link=static,shared stage
to start compiling. Be patience while boost is building, it takes a lot of time. When building is complete you can find the library files in "stage\lib" folder.
Also note that you can delete the folder "bin.v2" once building is complete.
Now you need to point your VS2010 project to those libraries. Modifying part of mlimber's answer:
In VS2010, right-click on your project, select Properties and then go to Configuration Properties -> Linker -> General. Look for "Additional Library Directories" in the middle of the list, and add C:\Program Files\Boost\boost_1_46_1\lib (or whatever) there.
Another way to do this is the following
In VS2010, right-click on your project, select Properties and then go to Configuration Properties -> VC++ Directories. Look for "Library Directories" in the middle of the list, and add C:\Program Files\Boost\boost_1_46_1\lib (or whatever) there.
Apart from the above, one could also download from
http://sourceforge.net/projects/boost/files/boost-binaries/1.46.1/
the necessary libraries (including the file missing).
While trying to build Pion network library, I ran into a very similar problem since Pion has dependency on Boost library.
My Boost build was built using boostrap and bjam, and not BoostPro.
The error I got was this: LINK : fatal error LNK1104: cannot open file 'boost_thread-vc100-mt-gd-1_46_1.lib'
When I looked at C:\OpenSource\boost_1_46_1\stage\lib directory, I saw every file name started with libboost_ and not boost_. The file boost_thread-vc100-mt-gd-1_46_1.lib was clearly missing. That made me suspicious that not all boost libraries were built by bjam. After a little research, I reran bjam with the option --build-type=complete
Now I noticed that it started creating lib file names starting with boost_. Not to mention, Pion library could now compile successfully.
Hope this adds some clarity to this thread.
Or alternatively to ybungalobill's suggestion use the installer from www.boostpro.com.
In the installer you must just select the boost versions for msvc 10 and after installation update your visual studio include and lib directories in the VS2010 property sheets to point to the boost include and lib directory.
I take it that you used the BoostPro installer, but which library types did you install -- header only, static linking, DLLs, everything?
Assuming you did everything, then the problem is probably that you don't have the path to boost in your library paths. The problematic file name starts with "libboost" which tells me you're trying to use the statically linked version, which is fine. You should add the library path to your Makefile or project settings for all build configurations. It's probably something like C:\Program Files\Boost\boost_1_46_1 (for the newest version on a 32-bit version of Windows).
In VS2010, right-click on your project, select "All Configurations" at the top, then go to Configuration Properties | Linker [or Librarian if you're making a library] | General. Look for "Additional Library Directories" in the middle of the list, and add C:\Program Files\Boost\boost_1_46_1\lib (or whatever) there.
Do that for each project in the solution that uses Boost libraries that are not header-only.
For a Makefile, you'll have to locate the library paths and add Boost to it similarly but by hand.