Jump to content

Compiler choices & linking APIs for C++

Guest
Go to solution Solved by geo3,

If you are on Windows Visual Studio is your best bet. Other wise use gcc.

What compiler do you use? 
Why do you use it?

How easy is it to setup new includes for API you download?

 

Long story of why I am making this thread:

Spoiler

I finally figured out how to make "cool things." One has to use an API and actually read the entire documentation from start to finish. CMake is also necessary & the user has to setup includes on their own so the compiler knows where the new APIs are. This was the hurdle that was holding me back IMO from making anything that wasn't if else & console. 

I'm looking for a C++ compiler that is compatible with CMAKE. I've been using Visual Studio 15 (2017) community. I'm curious if there are any more beginner oriented compilers that make it easier to setup includes that CMAKE supports. 

Link to comment
Share on other sites

Link to post
Share on other sites

Whatever the IDE comes with or gcc. It's mostly because I'm lazy and I'm familiar enough with gcc.

 

I say lazy in a way that I like my tools to be as easy as possible or can be configured in such a way to make it easy as possible. And if whatever tool is doing what I want, then I won't really spend energy tweaking it.

Link to comment
Share on other sites

Link to post
Share on other sites

16 minutes ago, geo3 said:

If you are on Windows Visual Studio is your best bet. Other wise use gcc.

Okay, I looked up a bit more about Visual Studio. I've had some trouble in the past, but I think I figured it out now. 

2 hours ago, M.Yurizaki said:

Whatever the IDE comes with or gcc. It's mostly because I'm lazy and I'm familiar enough with gcc.

 

I say lazy in a way that I like my tools to be as easy as possible or can be configured in such a way to make it easy as possible. And if whatever tool is doing what I want, then I won't really spend energy tweaking it.

I looked into this a little. I might learn it in the future. It looks powerful with being a whole Unix emulator. 

Link to comment
Share on other sites

Link to post
Share on other sites

4 hours ago, fpo said:

What compiler do you use? 
Why do you use it?

How easy is it to setup new includes for API you download?

 

Long story of why I am making this thread:

  Reveal hidden contents

I finally figured out how to make "cool things." One has to use an API and actually read the entire documentation from start to finish. CMake is also necessary & the user has to setup includes on their own so the compiler knows where the new APIs are. This was the hurdle that was holding me back IMO from making anything that wasn't if else & console. 

I'm looking for a C++ compiler that is compatible with CMAKE. I've been using Visual Studio 15 (2017) community. I'm curious if there are any more beginner oriented compilers that make it easier to setup includes that CMAKE supports. 

Cmake doesnt generate compilers, they generate build tools. In short, cmake is meant for crossplatform. It can generate make build files for linux, those for windows, and even visual studio projects. 

 

you choose cmake, you are pretty much gonna be working on applications that you are planning to deploy on other platforms. Compliers will then varied based on what platforms you are deploying,.=

 

 

Sudo make me a sandwich 

Link to comment
Share on other sites

Link to post
Share on other sites

2 hours ago, fpo said:

Okay, I looked up a bit more about Visual Studio. I've had some trouble in the past, but I think I figured it out now. 

visual studio is pretty awesome, and has grown a lot in the last few years. If you are doing windows C++ development, I highly recommend it. It's not perfect, but it has some pretty nice debugging features like intermediate compiler to execute statements in the breakpoint scope while your application is paused, a disassembler that conflates readable x86 with your source code, various performance profilers built in, and the ability to hook into existing processes for line debugging on anything that has an associated .pdb file.

Gaming build:

CPU: i7-7700k (5.0ghz, 1.312v)

GPU(s): Asus Strix 1080ti OC (~2063mhz)

Memory: 32GB (4x8) DDR4 G.Skill TridentZ RGB 3000mhz

Motherboard: Asus Prime z270-AR

PSU: Seasonic Prime Titanium 850W

Cooler: Custom water loop (420mm rad + 360mm rad)

Case: Be quiet! Dark base pro 900 (silver)
Primary storage: Samsung 960 evo m.2 SSD (500gb)

Secondary storage: Samsung 850 evo SSD (250gb)

 

Server build:

OS: Ubuntu server 16.04 LTS (though will probably upgrade to 17.04 for better ryzen support)

CPU: Ryzen R7 1700x

Memory: Ballistix Sport LT 16GB

Motherboard: Asrock B350 m4 pro

PSU: Corsair CX550M

Cooler: Cooler master hyper 212 evo

Storage: 2TB WD Red x1, 128gb OCZ SSD for OS

Case: HAF 932 adv

 

Link to comment
Share on other sites

Link to post
Share on other sites

47 minutes ago, wasab said:

Cmake doesnt generate compilers, they generate build tools. In short, cmake is meant for crossplatform. It can generate make build files for linux, those for windows, and even visual studio projects. 

 

you choose cmake, you are pretty much gonna be working on applications that you are planning to deploy on other platforms. Compliers will then varied based on what platforms you are deploying,.

I thought CMake made project files compatible with other programming environments. 

22 minutes ago, reniat said:

visual studio is pretty awesome, and has grown a lot in the last few years. If you are doing windows C++ development, I highly recommend it. It's not perfect, but it has some pretty nice debugging features like intermediate compiler to execute statements in the breakpoint scope while your application is paused, a disassembler that conflates readable x86 with your source code, various performance profilers built in, and the ability to hook into existing processes for line debugging on anything that has an associated .pdb file.

My main issue is trying to figure out how to get APIs like SDL & more to be used. 
I was wondering how to get languages like C to do more than display text in the terminal & so far all I figured is I somehow have to learn to compile libraries which I think have to be organized with CMake & then I have to figure out how to get an IDE to recognize that the API exists and know where it is and then be able to just type #include to finally be able to make something beyond if, int & print. 

Link to comment
Share on other sites

Link to post
Share on other sites

6 minutes ago, fpo said:

then I have to figure out how to get an IDE to recognize that the API exists and know where it is and then be able to just type #include to finally be able to make something beyond if, int & print. 

most IDEs im aware just need to know any referenced libraries. In Visual Studio, you just point to the .dll or .lib file in the project options, as well as the related header, and you should be good to go. Your linker should resolve the symbols from the .h your including with the library, as long as it's been compiled correctly. Linking is a C++ concept, and while the actual steps may differ for which IDE you are in, the IDE doesn't affect the underlying concept of linking libraries. Not to mention that you don't even NEED an IDE to do stuff like that, it just makes development in general a bit quicker/nicer.

Gaming build:

CPU: i7-7700k (5.0ghz, 1.312v)

GPU(s): Asus Strix 1080ti OC (~2063mhz)

Memory: 32GB (4x8) DDR4 G.Skill TridentZ RGB 3000mhz

Motherboard: Asus Prime z270-AR

PSU: Seasonic Prime Titanium 850W

Cooler: Custom water loop (420mm rad + 360mm rad)

Case: Be quiet! Dark base pro 900 (silver)
Primary storage: Samsung 960 evo m.2 SSD (500gb)

Secondary storage: Samsung 850 evo SSD (250gb)

 

Server build:

OS: Ubuntu server 16.04 LTS (though will probably upgrade to 17.04 for better ryzen support)

CPU: Ryzen R7 1700x

Memory: Ballistix Sport LT 16GB

Motherboard: Asrock B350 m4 pro

PSU: Corsair CX550M

Cooler: Cooler master hyper 212 evo

Storage: 2TB WD Red x1, 128gb OCZ SSD for OS

Case: HAF 932 adv

 

Link to comment
Share on other sites

Link to post
Share on other sites

8 minutes ago, reniat said:

most IDEs im aware just need to know any referenced libraries. In Visual Studio, you just point to the .dll or .lib file in the project options, as well as the related header, and you should be good to go. Your linker should resolve the symbols from the .h your including with the library, as long as it's been compiled correctly. Linking is a C++ concept, and while the actual steps may differ for which IDE you are in, the IDE doesn't affect the underlying concept of linking libraries. Not to mention that you don't even NEED an IDE to do stuff like that, it just makes development in general a bit quicker/nicer.

Will all built API have .h file extensions? 
I downloaded the SDL source code, configured with CMake, Generated & then found the .SLN in the file explorer. When I built, I didn't find any .h files in the Debug folder where the compiled API was placed. 

 

What is an alternative to linking with an IDE? Is the only other alternative to put all the source code into the project & reference it that way? 

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, fpo said:

Will all built API have .h file extensions? 
I downloaded the SDL source code, configured with CMake, Generated & then found the .SLN in the file explorer. When I built, I didn't find any .h files in the Debug folder where the compiled API was placed. 

 

What is an alternative to linking with an IDE? Is the only other alternative to put all the source code into the project & reference it that way? 

did you compile the library source? You can't take external source code and use it directly in your code unless you actually place that source code in your code. If you want to use it like a library, you need to compile the external source into a .dll or a .lib.

Gaming build:

CPU: i7-7700k (5.0ghz, 1.312v)

GPU(s): Asus Strix 1080ti OC (~2063mhz)

Memory: 32GB (4x8) DDR4 G.Skill TridentZ RGB 3000mhz

Motherboard: Asus Prime z270-AR

PSU: Seasonic Prime Titanium 850W

Cooler: Custom water loop (420mm rad + 360mm rad)

Case: Be quiet! Dark base pro 900 (silver)
Primary storage: Samsung 960 evo m.2 SSD (500gb)

Secondary storage: Samsung 850 evo SSD (250gb)

 

Server build:

OS: Ubuntu server 16.04 LTS (though will probably upgrade to 17.04 for better ryzen support)

CPU: Ryzen R7 1700x

Memory: Ballistix Sport LT 16GB

Motherboard: Asrock B350 m4 pro

PSU: Corsair CX550M

Cooler: Cooler master hyper 212 evo

Storage: 2TB WD Red x1, 128gb OCZ SSD for OS

Case: HAF 932 adv

 

Link to comment
Share on other sites

Link to post
Share on other sites

8 minutes ago, reniat said:

did you compile the library source? You can't take external source code and use it directly in your code unless you actually place that source code in your code. If you want to use it like a library, you need to compile the external source into a .dll or a .lib.

I took this folder

Spoiler

image.png.e029d9451de43633dc4eb82e4e057ff2.png

Configured CMake like so:

Spoiler

image.png.ab882e88a1f6725ef83606c573a4c9e9.png

opened the .sln that was created, right clicked the solution & selected build all to get the following:

Spoiler

image.png.855467ce07bab9210c11f61dc74ac2c0.png

EDIT:
This is the .zip I downloaded:

Spoiler

image.png.a97c79412f7af093207c0f005e6acacc.png

 

Link to comment
Share on other sites

Link to post
Share on other sites

I'll be honest I don't have much experience with Cmake, since the vast majority of my C++ work has been targeting just a single platform (windows). I know in visual studio, it's pretty straight forward: https://stackoverflow.com/questions/19384157/importing-a-lib-file-using-visual-studio

 

again though, I encourage you to keep in mind that linking is not IDE specific, only the way to get your IDE to do it for you changes from environment to environment. Understanding the linking process and the C++ source code lifecycle (how you get from your c++ source code to assembly, as well as loading libraries and different compiler options, etc.) is useful. You can theoretically just pass all the information in as flags for the compiler via CLI, but that can get REALLY painful if you have a lot of libraries (which is why things like Cmake and IDEs are useful)

Gaming build:

CPU: i7-7700k (5.0ghz, 1.312v)

GPU(s): Asus Strix 1080ti OC (~2063mhz)

Memory: 32GB (4x8) DDR4 G.Skill TridentZ RGB 3000mhz

Motherboard: Asus Prime z270-AR

PSU: Seasonic Prime Titanium 850W

Cooler: Custom water loop (420mm rad + 360mm rad)

Case: Be quiet! Dark base pro 900 (silver)
Primary storage: Samsung 960 evo m.2 SSD (500gb)

Secondary storage: Samsung 850 evo SSD (250gb)

 

Server build:

OS: Ubuntu server 16.04 LTS (though will probably upgrade to 17.04 for better ryzen support)

CPU: Ryzen R7 1700x

Memory: Ballistix Sport LT 16GB

Motherboard: Asrock B350 m4 pro

PSU: Corsair CX550M

Cooler: Cooler master hyper 212 evo

Storage: 2TB WD Red x1, 128gb OCZ SSD for OS

Case: HAF 932 adv

 

Link to comment
Share on other sites

Link to post
Share on other sites

5 minutes ago, reniat said:

I'll be honest I don't have much experience with Cmake, since the vast majority of my C++ work has been targeting just a single platform (windows). I know in visual studio, it's pretty straight forward: https://stackoverflow.com/questions/19384157/importing-a-lib-file-using-visual-studio

I kinda get it as I found the following video (He begins talks about linking around 6:14)

Spoiler

 

though he types 

#include "Engine.h"

which has the .h file extension. 

5 minutes ago, reniat said:

again though, I encourage you to keep in mind that linking is not IDE specific,

I was actually hoping for this because last time I tried using Visual Studio to do this, things got confusing for me. 

5 minutes ago, reniat said:

only the way to get your IDE to do it for you changes from environment to environment. You can theoretically just pass all the information in as flags for the compiler via CLI,

I don't know how to use the Command Prompt to interact with any programs. Are you telling me this is the method you're talking about? 

5 minutes ago, reniat said:

but that can get REALLY painful if you have a lot of libraries (which is why things like Cmake and IDEs are useful)

I'm not 100% sure what CMake is/does. I think it converts project file structures to formats for other programming environments. I have 2 C++ textbooks and neither really go into anything besides if, else, making a new project, classes and all that "basic" general kind of stuff. 

Link to comment
Share on other sites

Link to post
Share on other sites

For using 3rd party libraries like SDL in Visual Studio you can use VCPKG. You tell it which version of the library to install (32 or 64 bit, static or dynamically linked) and it will automatically download, build and add the proper compiler and linker options for you to use the libraries in your projects. Not every library will be available but a ton are.

1474412270.2748842

Link to comment
Share on other sites

Link to post
Share on other sites

20 hours ago, fizzlesticks said:

For using 3rd party libraries like SDL in Visual Studio you can use VCPKG. You tell it which version of the library to install (32 or 64 bit, static or dynamically linked) and it will automatically download, build and add the proper compiler and linker options for you to use the libraries in your projects. Not every library will be available but a ton are.

Is there a way to install it with Visual Studio?

I found this and downloaded a .zip from github. 

After following the README 

Spoiler

Run the batch file in Command Prompt, run a few commands & then try the command:


vcpkg install sdl2 curl

 

I haven't seen any way to link it with Visual Studio through the README nor the initial link. 

Was there a guide you found helpful? Or did you learn this in your schooling? 

Link to comment
Share on other sites

Link to post
Share on other sites

1 hour ago, fpo said:

I haven't seen any way to link it with Visual Studio through the README nor the initial link. 

Was there a guide you found helpful? Or did you learn this in your schooling? 

I just followed the quick start section on the github page then googled if I couldn't figure something out. 

There is no linking to VS, the program edits some internal VS files to make things available in any project (if you did the integrate step in the guide.)

 

vcpkg install sdl2 curl

installs the 32bit dynamically linked versions of the libraries so make sure your project is set to x86

 

if you want to get the 64 bit version use

vcpkg install sdl2:x64-windows

 

and for statically linked (if the library supports it, I don't know if sdl or curl do)

vcpkg install sdl2:x86-windows-static

for 32bit or

vcpkg install sdl2:x64-windows-static

for 64bit

 

After installing you should be able to just #include <SDL2/sdl.h> and everything should work automatically.

 

 

1474412270.2748842

Link to comment
Share on other sites

Link to post
Share on other sites

On 8/29/2018 at 10:56 PM, fizzlesticks said:

snip

This seemed to work very well however I had some trouble following the SDL guide. 
I ended up finding this tutorial that covers how to use the Linker in VS. 
After following your software ideal, I was a bit confused as to why functions were purple but hadn't had enough time to focus on it. 

Poor timing just got really busy. 

Thanks to everyone for your help! 

Link to comment
Share on other sites

Link to post
Share on other sites

31 minutes ago, fpo said:

This seemed to work very well however I had some trouble following the SDL guide. 
I ended up finding this tutorial that covers how to use the Linker in VS. 
After following your software ideal, I was a bit confused as to why functions were purple but hadn't had enough time to focus on it. 

If you use vcpkg you shouldn't need to do anything but the last step from that tutorial to set the subsystem (if you want something besides the default.)

 

And I use dark theme so purple is just a normal color for me so I have no idea what that might mean.

1474412270.2748842

Link to comment
Share on other sites

Link to post
Share on other sites

2 hours ago, fizzlesticks said:

If you use vcpkg you shouldn't need to do anything but the last step from that tutorial to set the subsystem (if you want something besides the default.)

 

And I use dark theme so purple is just a normal color for me so I have no idea what that might mean.

It’s dark in purple theme haha. 

Link to comment
Share on other sites

Link to post
Share on other sites

CMake lets you script the inclusion of project relevant files and dependencies and much more in its CMakeLists.txt. Executing it generates build files (e.g. Makefile or Visual Studio files) for the project. CMakes find_package scripts can give you the locations of installed library and header files, which can then be included in the project.

cmake_minimum_required(VERSION 3.8) # Minimal CMake version
project(app_project) # Project name

set(CMAKE_CXX_STANDARD 14) # Set C++ version variable

find_package(some_library REQUIRED) # Find some_libray and fail if not found
find_package(other_library REQUIRED)

add_executable(myapp main.cpp other.h other.cpp) # Link project files to exe
target_link_libraries(myapp some_library other_library) # Link libraries to exe

CMake provides find_package scripts for many libraries for different platforms, but sometimes you need to write your own or just manually include the location of the files. There are many tutorials for CMake online.

 

CLion integrates deeply with CMake and bundles a MinGW GCC for Windows. Visual Studio can be made to work with CMake as well.

My boring Github   /人◕ ‿‿ ◕人\

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×