Jump to content

New to Hardcore programming

I have been webdesigning for almost 5 years and C programming Arduinos and ESP for almost a year, so i decided to enter the realm of hardcore programming and start with loading a grapghic library GTK+ on my IDE. I use 2 IDE, Dev C++ and Visual Studio 2017.

But for some reason, i can't make the library work. There is always some kind of issue somewhere. I would really appreciate if someone can answer me to quesions:

1. Why isn't there a decicated C file/project option in visual studio (when C is one of the most important languages)?

2. Why is the installation of libraries so complicated? Can't there be some kind standard? I mean, can't i just download the library? And install it directly from the IDE itself?

3. If GTK+ one of the major Graphic libraries for C, C++, Python, C# , why is it's webpage so crappy? Why are the tutorials outdated? 

Link to comment
Share on other sites

Link to post
Share on other sites

48 minutes ago, AKJ said:

1. Why isn't there a decicated C file/project option in visual studio (when C is one of the most important languages)?

Visual Studio's C++ compiler works just fine with C, so there's no need to make a distinction between C/C++ as far as Visual Studio is concerned.

48 minutes ago, AKJ said:

2. Why is the installation of libraries so complicated? Can't there be some kind standard? I mean, can't i just download the library? And install it directly from the IDE itself?

If this is Windows and Visual Studio, the library should be in the form of a DLL file that you can import as a reference into your project. See https://msdn.microsoft.com/en-us/library/ms235636.aspx

 

This is somewhat convoluted to set up in Linux as well. At least if you want to do things manually (and even then, tools that help automate the process probably don't make the process any easier)

48 minutes ago, AKJ said:

3. If GTK+ one of the major Graphic libraries for C, C++, Python, C# , why is it's webpage so crappy? Why are the tutorials outdated? 

Being a GUI library doesn't mean the web page has to be extravagant and fancy. Windowing programming on an OS is different than that of HTML documents. And if the tutorials cover the basics to get you going, there's no real need to update them. The C standard book, the one by Kerningham and Ritchie hasn't been updated since C89, and yet it's still used as a reference book for C even though C has had updates to the standard. Does it matter if the original book doesn't talk about C99 data types or inline functions? No, not really. It covers much of the foundations one needs to write C programs.

Link to comment
Share on other sites

Link to post
Share on other sites

2 minutes ago, M.Yurizaki said:

Visual Studio's C++ compiler works just fine with C, so there's no need to make a distinction between C/C++ as far as Visual Studio is concerned.

Visual Studio's compiler doesn't support standard C and it never will. If you want to write straight C code you shouldn't be using VS.

1474412270.2748842

Link to comment
Share on other sites

Link to post
Share on other sites

5 hours ago, M.Yurizaki said:

You can switch the compilers to something else if you really want it to support standard C.

This is exactly what i mean.

I wanted to create a C file to run. But it seems, i can only run C files in Projects.

I create an empty C++ project. Test out 

#include "stdafx.h"

int main(){
	printf("Hello World\n");
  	return 0;
}

The code run, the console opens and quickly closes. 

I then search how to run C codes online and did what they suggested.

I created a C++ console application, created a C++ files in the application and run the code above, which was a success.

But i want C files, i change the compiler to compile only as C and i renamed the file to "main.c". The code runs, but when i try 

#include "stdafx.h"
  
int main(){
	int x = 10;
  	int *ptr;
  	ptr = &x;
  	printf("%d", *ptr);
  	return 0;
}

The syntax ("%d") is not recognized and the code doesn't run.

Link to comment
Share on other sites

Link to post
Share on other sites

5 hours ago, M.Yurizaki said:

Being a GUI library doesn't mean the web page has to be extravagant and fancy. Windowing programming on an OS is different than that of HTML documents. And if the tutorials cover the basics to get you going, there's no real need to update them. The C standard book, the one by Kerningham and Ritchie hasn't been updated since C89, and yet it's still used as a reference book for C even though C has had updates to the standard. Does it matter if the original book doesn't talk about C99 data types or inline functions? No, not really. It covers much of the foundations one needs to write C programs.

What bothered me was the lack of instructions, of examples. Most tutorials online are about GTK+ 2 on Windows 32 computers or the new ones are for C# or C++. This is the 3rd day, i am trying to install GTK3+, i would appreciate it, if you could help me.

Link to comment
Share on other sites

Link to post
Share on other sites

10 hours ago, M.Yurizaki said:

If this is Windows and Visual Studio, the library should be in the form of a DLL file that you can import as a reference into your project. See https://msdn.microsoft.com/en-us/library/ms235636.aspx

A DLL file is only used by the application at run time, when it dynamically links against it. During development you need the header files that contain the declarations of the entities you want to use and the object file (.lib, .obj, .o, depending on system/compiler) to link against.

 

11 hours ago, AKJ said:

2. Why is the installation of libraries so complicated? Can't there be some kind standard? I mean, can't i just download the library? And install it directly from the IDE itself?

It's not really that complicated once you understand the compilation/linking process - I have a hunch you don't - So I'd suggest studying that further first.

 

As said, you need the header files (and add the folder they're in to the compiler's header search path), and the object files (and add to the linker search path). Since each compiler/system implements object files differently, it's typical for a library to supply the source code and you'll have to build the object files yourself. However, a quick glance shows that this library has some dependencies of itself, which possibly due to legal reasons cannot be supplied directly with the GTK download, so you might have to download and build those first, and so on.

 

There exist some library package managers that automate installation of supported libraries, you can try some of them and see if any supports the libraries you need.

 

The reason there isn't any standard should be obvious. Object files are compiled machine code, so they will naturally be different for different systems. It would also hamper innovation if they were standardized, since no-one would be allowed to invent and create better implementations.

4 hours ago, AKJ said:

The syntax ("%d") is not recognized and the code doesn't run.

You need to include stdio.h for printf and it's format specifiers.

Link to comment
Share on other sites

Link to post
Share on other sites

I use Pelles C. It’s free from some German organization I believe. 

 

For robots, I used robotc as I had Mindstorms and vex to work with. 

 

Otherwise I'm sure you’re well acquainted with the arduino program environment. 

 

If you program windows desktop apps for personal use, I recommend C# and Windows Forms. You can drag the text boxes and buttons wherever you want on the screen. Otherwise there’s an xml html thingy you can type in to get the user interface to look how you want. Most of the basic stuff is the same. 

Spoiler

int Variable = 5;

float number =0.5f;

if (true) 

print (“always executes.”); 

else

print (“your computer is broken.”);

for (int i =0; i < Variable; i++){

print(i);

}

do{

print(“crash”);

}

while(true);

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

  • 2 weeks later...

Visual Studio is absolute trash if you don't have Resharper and even then it's barely usable. I suggest you get mingw+cmake+clion instead of trying to get VS to do what you want it to do. Also it'll be easier if you switch to Linux since then you'll just need CLion and things will just work. Although I should mention you'll need to somewhat figure out how cmake works which at least as far as basic stuff goes isn't too difficult.

Link to comment
Share on other sites

Link to post
Share on other sites

  • 2 weeks later...
On 2018-05-19 at 9:25 PM, M.Yurizaki said:

Visual Studio's C++ compiler works just fine with C, so there's no need to make a distinction between C/C++ as far as Visual Studio is concerned.

If this is Windows and Visual Studio, the library should be in the form of a DLL file that you can import as a reference into your project. See https://msdn.microsoft.com/en-us/library/ms235636.aspx

It works fine with ANSI C (C89), and most C99 features. The Visual C++ team doesn't plan on supporting modern C standards to the fullest though is the thing since C++ is their main focus. There definitely is a reason to make a distinction between C/C++ with Visual Studio because it has options to compile C or C++ code or determine how to compile the files based on the file extension (cpp vs c). Also, if you're compiling some C code, C isn't as strict with the requirement to case void pointers and in C this is actually discouraged for several reasons, sizeof char literals is 1 in C++ and 4 in C, among many other things. There's also other differences at the heart of both languages so you'd best know what you're actually trying to write - C or C++, there is no in between.

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

×