Showing posts with label mingw. Show all posts
Showing posts with label mingw. Show all posts

Friday, May 24, 2013

Compiling Geany on Windows

Can't remember exactly how many times I've tried compiling Geany or even thought of trying to compile it on Windows.  But I remember that my last try was last 2011 -- about February or March.

It's been a while that I've been trying to find a stable and reliable free and open source (not to mention cross-platform) Source Code Editing software so I could strip it down to provide an IDE specifically functioning for my open source game creation project called KAGE.  Finally, -- finally! -- I successfully compiled it yesterday!

I know that Geany's project page has a how-to page for compiling it on Windows but I still had bumps along the way.  This tutorial is simply to compliment what seems to be missing in the official tutorial.

So, just a recap. You need to have this things done already:

Not sure if we also need the GtkMM for Scintilla, but I did have that installed on my machine before I tried compiling Geany for the last time.

Before we proceed, let's make sure that you had the contents of GCC and GTK+ under C:\libs directory.  And that C:\libs\bin is added on your %PATH%, as well as C:\libs\msys\1.0\bin.

Now, for the `complimentary' part of my tutorial.

First, download the Manifest file from Geany's Git repo, which was not included in the downloadable zipped source code.

Rename win32-config.h to config.h then change the content of makefile.win32 from

all: config.h
 $(MAKE) -C tagmanager/ctags -f makefile.win32
 $(MAKE) -C tagmanager/mio -f makefile.win32
 $(MAKE) -C tagmanager/src -f makefile.win32
 $(MAKE) -C scintilla -f makefile.win32
 $(MAKE) -C plugins -f makefile.win32
 $(MAKE) -C src -f makefile.win32

config.h: win32-config.h
 $(CP) $< $@


to this

all: $(MAKE) -C tagmanager/ctags -f makefile.win32
 $(MAKE) -C tagmanager/mio -f makefile.win32
 $(MAKE) -C tagmanager/src -f makefile.win32
 $(MAKE) -C scintilla -f makefile.win32
 $(MAKE) -C plugins -f makefile.win32
 $(MAKE) -C src -f makefile.win32


The reason behind is that, there seems to be wrong with the makefile that the command COPY thinks config.h is supposed to be a directory.

Now, open a command line then run cd to the directory where you extracted Geany's source code.

Finally, type-in: make -f makefile.win32

Wait for it to compile and you'll then end up a very fresh build of Geany on Windows.

~creek23

Sunday, March 20, 2011

GCC: G++ ifstream reads extra unwanted characters

Been having trouble with GCC's G++ 4.5.2 with MinGW on Windows. I kept having unwanted characters from a file, which should not be present in the first place.

Given that I have a hello.txt text file that contains,
Hello World
and
Hello Universe


when opened with Notepad or any other text editor, G++ keeps sending me,
Hello World
and
Hello Universe
zpzksmsm3jk4509s


Of course, "zpzksmsm3jk4509s" is just a representation of the garbage data I'm getting. Most of the time, that garbage data is readable. So I usually get something like,
Hello World
and
Hello Universe
He


So there is basically no way for me to know which is a garbage data and which is still part of the file. Somehow, getting the file size doesn't seem to work correctly.

string loadFile(string p_fileName) {
  const char *l_fileName = p_fileName.c_str();
  char *bufPath = new char[strlen(l_fileName)];
    strcpy(bufPath,l_fileName);

  ifstream file(bufPath, ios::in|ios::ate);
  ifstream::pos_type size;
  char * memblock;
  string ret;

  size = file.tellg();
  memblock = new char [size];

  file.seekg (0, ios::beg);
    file.read (memblock, size);
  file.close();

  ret = memblock;
  delete []memblock;
  delete []bufPath;

  return ret;
}


Just so you could follow me further, I am trying to make a simple interpreter. I am barely at the part where I have to tokenize the text content and just had a basic checking of which is a command and which is not.

As I run my interpreter, I get the "expected" error, "Unknown command ` zpzksmsm3jk4509s'". But it's the "zpzksmsm3jk4509s"-part of the message that I was not expecting. As I said, the text file only contains nothing more but
Hello World
and
Hello Universe


It took me a couple of days before finally figuring out the problem.

According to a Cygwin FAQ entry, there seem to be an abnormality with Windows dealing with CR/LF.

From a Notepad's perspective, the hello.txt file is only 32bytes long. That counts Hello World (11 bytes), and (3 bytes), Hello Universe (14), plus two instance of CR and LF (thus, 4bytes).

G++ on Windows, on the other hand, also sees 32bytes. But! As what the Cygwin FAQ page says, it seems, Windows gives you CR and LF as one single character. Meaning, you, as the coder, should only read 30bytes long. That's why G++ is giving me extra He content.

So I had to modify my loadFile from reading the content all at once, into reading the content one character after the other. Then upon reading an 'LF', I will try to check if 'CR' was the previous character, giving me a CR/LF. In which, I will have to lessen my expected length in each instance of a CR/LF.

My code looked sort of something like this.
  int i = 0;
  file.seekg (0, ios::beg);
  while (file.eof() == false) {
    memblock[i] = (char) file.get();
    if (memblock[i] == '\n') {
      if (i > 0 && memblock[i-1] == '\r') {
        memblock[i-1] = '\n';
        i--;
      }
    }
    i++;
  }


Then make sure the last character of memblock would be a string-terminating "\0" since memblock is not a C++ String but a char*.

Now, if you ask, why did you get a CR then LF if Windows only gives you CR/LF as single character? Well, it seems, if you will have to read the file one character after the other, CR won't be CR/LF but simply CR. Making the next simply LF. You could assume that it's more of a G++ problem than a Windows problem. But as the Cygwin FAQ page suggests, it is a Windows file-handling problem.

Saturday, February 12, 2011

MSYS pr not found

Ever got the pr not found error on MSYS?

Not sure why the packages made pr command to be obsolete. But compiling FFMPEG on Windows using MinGW and MSYS requires pr in the toolchain.

Do not worry, it is still on MinGW's download page though not easily accessible. It's hidden inside MSYS/BaseSystem/msys-core/obsolete

But be careful, you will only need the PR.EXE, everything else is unnecessary.

UPDATE: Updated link.

Thursday, March 4, 2010

Getting Started with GTK on Windows

I am assuming that you already know GTK+ and wanted to try it out for the first time. This article will discuss how to setup your development environment to start writing GTK+ based applications.

First things first, download everything you need.

Download GTK from GTK.org -- I downloaded gtk+-bundle_2.18.7-20100213_win32.zip.

Optionally, download libiconv from GTK.org -- as of this writing libiconv is version 1.9.1.

For C editor, I am using MinGW Developer Studio. It is the easiest to setup in compiling GTK+ applications since it already works well with MingGW, the recommended toolchain when using GTK. Sadly, the developer's website is somewhat down or possibly currently doing a revamp. But you can easily get version 2.0.5 from list of mirrors courtesy of TextEditors.org.

Setting them up

Install MinGW Developer Studio.

Extract gtk+-bundle_2.18.7-20100213_win32.zip then place content in C:\Gtk+\{here}

Same with libiconv, extract libiconv-1.9.1.bin.woe32.zip then place all contents in C:\Gtk+\{here}

Configuring MinGW Develop Studio.
  1. Launch the editor
  2. Click Edit -> Options... to open the Option dialog box.
  3. Click the Directories tab
  4. On Show directories for,
    • select Include files then add the following paths:


      • C:\Gtk+\include
      • C:\Gtk+\lib\glib-2.0\include
      • C:\Gtk+\lib\gtk-2.0\include
      • C:\Gtk+\include\cairo
    • select Library files then add this path:


      • C:\Gtk+\lib
Testing it out.
  1. Launch MinGW Developer Studio
  2. Click Project -> New Project to open New dialog box.
  3. Select GTK+ Application and indicate HelloGTK as Project Name
  4. Click OK to create new project.
  5. Click File -> New to open New dialog box.
  6. Select C/C++ Source File and indicate hellogtk.c as File name.
  7. Click OK to create new file.
  8. Type in the code below then press F5 to compile and run the program.

If you are having problem running you hellogtk application, you might need to install GTK+ runtime. I use GIMP, which installs the runtime -- try to download and install a copy of GIMP for Windows.

Where to go from here? Read the official documentation and tutorials.