Viewing CPython Code in CLion - c

Sorry for a question that might appear stupid to more experienced developers: I am still a newcomer to C and C++.
I come from Python/Java development land and am trying to get a better insight into C and C++. I installed JetBrains CLion and cloned CPython mercurial repository. However when I started looking at the source code, I realized that Clion was highlighting a lot of constructs that seemed to be working. For instance:
Or
As far as I can see, Clion seems the have problem with the identation style of Python, C code, but once again, I might be wrong.
How Clion configurations can be altered for it to properly parse the CPython code?

CPython uses GNU Autotools for the build, but that toolset is not supported by CLion. See issues CPP-494 and CPP-193. CLion currently supports only one build system - CMake.
You can create your own CMakeLists.txt file and list the sources in there. This will help CLion to understand the structure of the source tree and allow it to find the headers etc:
cmake_minimum_required(VERSION 3.0)
project(cpython)
file(GLOB SOURCE_FILES
Python/*.c
Parser/*.c
Objects/*.c
Modules/*.c)
include_directories(Include)
add_executable(cpython ${SOURCE_FILES})
For the actual build, use standard build tools from command line. Alternatively, custom command can be added to CMakeLists.txt to call make. See add_custom_command for that.

As mentioned in the above answer you need a CMake Project to allow CLion to build Python.
In fact there is already a CMakeList.txt-files for CPython, that is maintained independently from the official sources:
https://github.com/python-cmake-buildsystem/python-cmake-buildsystem
I didn't test it with CLion but it should do the job...

Related

(C) How to link dlls within CLion

I've been programming C for a while with Visual Studio, but now switched to CLion. My programming and target system is Windows10.
Within Visual Studio, I was able to include the required DLLs like "vcruntime140d.dll" and "ucrtbased.dll" inside my exe.
I did this by going into the project settings and set configuration settings - C/C++ - code generation - runtime library to "Multithreaded-Debug (/MTd)".
Doing this I was able to run the resulting exe without having errors like "vcruntime140d.dll is missing" or "ucrtbased.dll is missing".
But how can I achieve this within CLion?
I've been searching for a while now, and I found a lot of tutorials on how to include .lib files but not for DLLs (I don't have the code for).
With Clion, you actually are working with CMake. So the question is to be like how to link dlls within CMake.
There are many ways to do. e.g.
link_libraries
target_link_libraries
If the library could not be found by default, use find_library to search for it.
If these functions seems too strange to you, check this tutorial from the CLion team.
Update
As in the comment you asked, your problem is how to load a dll without lib. To address this, you could dynamicly load the dll, or make a lib from the dll.
For Windows multicopies problem, add following into your CMakeLists.txt
foreach (flag_var
CMAKE_C_LINK_FLAGS
CMAKE_C_LINK_FLAGS_DEBUG
CMAKE_C_LINK_FLAGS_RELEASE
CMAKE_CXX_LINK_FLAGS
CMAKE_CXX_LINK_FLAGS_DEBUG
CMAKE_CXX_LINK_FLAGS_RELEASE
CMAKE_EXE_LINKER_FLAGS
CMAKE_EXE_LINKER_FLAGS_DEBUG
CMAKE_EXE_LINKER_FLAGS_RELEASE
CMAKE_C_FLAGS
CMAKE_C_FLAGS_DEBUG
CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_MINSIZEREL
CMAKE_C_FLAGS_RELWITHDEBINFO
CMAKE_CXX_FLAGS
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL
CMAKE_CXX_FLAGS_RELWITHDEBINFO)
string(REPLACE "/MD" "-MT" ${flag_var} "${${flag_var}}")
endforeach ()

CLion does not recognize CMakeLists.txt file

I am currently trying to set up CLion, as I like IntelliJ a lot, and I ran into this seemingly very basic problem:
CMake Error: The source directory "/cygdrive/c/.../untitled" does not appear to contain CMakeLists.txt.
Specify --help for usage, or press the help button on the CMake GUI.
This happens even when building a clean C project from scratch in CLion, where a CMakeLists.txt file is present in exactly that directory. I use cygwin64 as compiler and work on a Windows x64 machine. I guess /cygdrive/ before c is due to that.
Sorry to bother you guys with that basic stuff, but I simply cannot work it out. I know there are a lot of similar questions around, unfortunately that did not help me.

How to build GLUS with MinGW and Sublime Text 3

I am in a similar situation :
Eclipse CPP and GNU following these instructions. But i need to build GLUS with MinGW and sublime text.
I am learning C and OpenGL ,so i lack compilation/dependencies logic.
I would just like to undertsand in a simple way.
how to compile GLUS from those source:
https://github.com/McNopper/OpenGL/tree/master/GLUS/src
Where to install all the files in MinGW folder to setup things correctly.
Glew and Glfw are already configure correctly and works fine.
Thanks for your time.
Well Norbert Nopper kindly answer my question directly. And like the answer mention above. The path to follow to compile GLUS without any ide is by using cmake.
in the GLUS folder, there is a CMake file (https://cmake.org/). With
CMake, you can create the GLUS library without any IDE and for a lot
of platforms – including Windows and MinGW.
Yes cmake is the answer.
You usually create a build directory. Inside your git clone of the repository you do :
mkdir build
cd build
cmake ..
make

How to use CUDA 6.0 with XCODE 5

My question may completely be a noob. Sorry, for that but I have been trying to compile my first Cuda code in Xcode and I'm lost where and how I could set up the IDE to invoke NVCC.
I installed the latest CUDA toolkit CUDA 6.0 and have even installed GCC 4.8 using brew. I have XCODE 5.5
When I run my code from XCODE all the directives like global are marked as unidentified.
I don't where and to change the settings to invoke NVCC. I will be really thankful, if anyone could help me with this.
Further, when I created the XCODE project, I created it as a C project. So, I placed the CUDA code in this C file, which is what is giving me the above mentioned errors. I tried to replace this .C file with a .cu file (just change the extension), which too failed badly - XCODE didn't even know what to do with the .cu files
COuld anyone please help me?
Thanks in Advance
I have given it a try. Although I have not completely succeeded I thought I'd post my progress here in hopes of helping others. The steps I took were inspired by this page.
Create a new Xcode project
Under Build Settings add a new user defined setting CC with the value /usr/local/cuda/bin/nvcc.
Add /usr/local/cuda/include to Header Search Paths under Build Settings.
Set Enable Modules (C and Objective-C) to No.
Add /usr/local/cuda/lib/libcuda.dylib to Link Binary With Libraries under Build Phases.
For any C files you create set their extension to .cu in the File Inspector, after you have done that you have to set the type of that file to C source to get syntax highlighting, by going to Editor->Syntax Coloring->C.
Problems with this setup:
- Xcode can't run the executable, at least nog if it is compiled for debugging. However you can make it copy the executable to some reasonable location and run it in the terminal.
- Whenever you try 'Build for running' sometimes Xcode magically destroys the whole project.

How to build gnu `libiconv` on & for windows?

I want to build a static library (*.LIB file) GNU libiconv on windows to be used with other libraries in Visual C++. Other libraries I'm using are built with "MultiThreaded DLL" (/MD) Runtime option. So, I need to build libiconv with the same option.
Problem is the libiconv uses GNU build system and I want to compile with /MD option. You can see the source structure of libiconv here:
http://cvs.savannah.gnu.org/viewvc/libiconv/?root=libiconv
Mr. Zlatkovic maintains the windows port of GNU libiconv for libxml2
you can see them here:
ftp://xmlsoft.org/libxml2/win32/iconv-1.9.2.win32.zip
I cannot use his port. I need to build from the latest version of libiconv-1.13. I wonder how this guy has ported it? Can some one please tell me how to build *.lib from this and compile it using MSVC?
EDIT:
Actually, I need to build few more gnu libraries with same settings. So, if I get solution for one library. I can do the same for all others.
I found PARK Youngho's How to Build libiconv with Microsoft Visual Studio over at The Code Project to be complete and clean (for VS2010 and GNU libiconv 1.14).
A little addition to your answer.
I had the same issue and found that the MinGW + MSYS solution was perfect.
Though, I needed to go a little further and generate also the .lib file in order to be able to link with the resulting dll.
This is what I found:
generate a .def file from the dll with dumpbin (a Visual Studio tool).
generate the .lib file from the .def with the lib program (Visual Studio tool too)
This allows you to specify some link flags if appropriate.
Everything detailed here (I'm not the author of this method):
http://wiki.videolan.org/GenerateLibFromDll
I also realized that this lib/dll couple can be linked with both MD and MDd libraries.
Hope that can help people that find this post, like it helped me.
-David
I'm the OP. MSYS is the exact thing what I was looking for.
Just install MinGW & MSYS which contains shell sh.exe & make.exewith which you can configure and generate a Makefile after that you can use make.exe to run it.
Its as simple as that.
compile them using MinGW using Msys for the environment if needed. MinGW's .a files are apparently, according to the mailing list, the same format as .lib files (just do a rename). You might want to check first to see if the iconv static library is included already in the MinGW download / filesystem.
Edit: it's in msys (C:\msys\1.0\lib), along with:
libiconv.a
libiconv.dll.a
libiconv.la
and additionally
libiconv-2.dll (in C:\msys\1.0\local\bin)
Edit: is it in here, the libiconv you need? these versions seem to have MSVC makefiles :) http://www.opensource.apple.com/source/libiconv/

Resources