Developer forums (C::B DEVELOPMENT STRICTLY!) > Development

Build C::B against wx3.02 with gcc 5.2 under Windows

<< < (11/25) > >>

stahta01:
Here is an example of the header to include in sdk_common.h in place of wxprec.h include.

Then there will only be 2 or 3 likely places to fix. Or we could just add the wx headers that we do NOT have in  sdk_common.h to that file. There is a wx header IIRC, the dnd.h header that will need added to sdk_common.h or included in the CB_PRECOMP headers list.


--- Code: ---/////////////////////////////////////////////////////////////////////////////
// Name:        wx_wrap_win_headers.h
// Purpose:     Includes the appropriate headers to avoid errors
//              Based on the wx/wxprec.h header created by Julian Smart
// Author:      Tim S.
// Modified by:
// Created:     2015-10-05
// Copyright:   (c) Julian Smart
// Licence:     wxWindows licence
/////////////////////////////////////////////////////////////////////////////

#ifndef WX_WRAP_WIN_HEADERS_H
#define WX_WRAP_WIN_HEADERS_H

#include <wx/defs.h>     // Multiple wx headers error out without this include before them.
#include <wx/version.h>  // Needed for wxCHECK_VERSION

// include the header that defines UNICODE macro correctly
// _before_ including <windows.h>
#if wxCHECK_VERSION(2, 9, 0)
#include <wx/chartype.h>
#else
#include <wx/wxchar.h>
#endif

// include standard Windows headers
#if defined(__WINDOWS__)
    #include <wx/msw/wrapwin.h>
    #include <wx/msw/private.h>
#endif
#if defined(__WXMSW__)
    #include <wx/msw/wrapcctl.h>
    #include <wx/msw/wrapcdlg.h>
    #include <wx/msw/missing.h>
#endif

#endif // WX_WRAP_WIN_HEADERS_H

--- End code ---

Tim S.

ollydbg:

--- Quote from: ollydbg on October 05, 2015, 04:30:46 pm ---
--- Quote from: stahta01 on October 05, 2015, 12:46:52 pm ---I agree that setting WX_PRECOMP in any cbp files is NOT needed or wanted. But, remember for Windows we still need both headers sdk.h and sdk_precomp.h (might have misspelled the second one).

--- End quote ---
Yes, there are still two gch files (sdk.h.gch and sdk_precomp.h.gch), and I think they are used to handle the __declspec (dllimport) and __declspec (dllexport) differences.
But do we really need that? WIN32 - ld says that we don't need to specify those import or export attribute.

1, I see that when bulding the sdk, we already have an option: "-Wl,--export-all-symbols", from the above document, this means all the symbols will be exported (whenever the symbol have dllexport or not)
2, I see that all target(either sdk or src or other plugins) have "-Wl,--enable-auto-import", this means the "ld" can handle the symbol import quit well
3, maybe, we need to add another linker option: "--enable-runtime-pseudo-relocs" to handle the import issue, as also statement in the ld document.

I haven't tried it yet, It's great if we can keep only one pch file.

--- End quote ---

Some good news:
I was thinking to merge the two pch files to only one, here is the reference page I followed:
HOWTO Create and Deploy a Sample DLL using MinGW | MinGW
And I did the following:
1, example_dll.h, this file is modified from the one in above link, and add a #ifdef NOPORT, so that I can remove the __declspec kinds of decorations.

--- Code: ---#ifndef EXAMPLE_DLL_H
#define EXAMPLE_DLL_H

#ifdef __cplusplus
extern "C" {
#endif

#ifdef NOPORT
    #define EXAMPLE_DLL
#else
    #ifdef BUILDING_EXAMPLE_DLL
        #define EXAMPLE_DLL __declspec(dllexport)
    #else
        #define EXAMPLE_DLL __declspec(dllimport)
    #endif   
#endif

void __stdcall EXAMPLE_DLL hello(const char *s);

int EXAMPLE_DLL Double(int x);

#ifdef __cplusplus
}
#endif

// NOTE: this function is not declared extern "C"
void EXAMPLE_DLL CppFunc(void);

// NOTE: this class must not be declared extern "C"
class EXAMPLE_DLL MyClass
{
public:
        MyClass() {};
        virtual ~MyClass() {};
        void func(void);
};

#endif  // EXAMPLE_DLL_H

--- End code ---

2, example_dll.cpp, which is copied from the above link:

--- Code: ---#include <stdio.h>
#include "example_dll.h"

__stdcall void hello(const char *s)
{
        printf("Hello %s\n", s);
}
int Double(int x)
{
        return 2 * x;
}
void CppFunc(void)
{
        puts("CppFunc");
}
void MyClass::func(void)
{
        puts("MyClass.func()");
}

--- End code ---

3, example_exe.cpp, which is also copied from the above link:

--- Code: ---#include <stdio.h>
#include "example_dll.h"

int main(void)
{
        hello("World");
        printf("%d\n", Double(333));
        CppFunc();

        MyClass a;
        a.func();

        return 0;
}

--- End code ---

4, the command I use to create the dll and the exe, and run the exe, I get the correct result

--- Code: ---D:\test\test-dll>g++ -c -DNOPORT example_dll.cpp

D:\test\test-dll>g++ -shared -o example_dll.dll example_dll.o -Wl,--export-all-symbols

D:\test\test-dll>g++ -c -DNOPORT example_exe.cpp

D:\test\test-dll>g++ -o example_exe.exe example_exe.o -L. -lexample_dll


D:\test\test-dll>example_exe.exe
Hello World
666
CppFunc
MyClass.func()

D:\test\test-dll>


--- End code ---

5, Look at the two "g++ -c" command, I think it is a good place here that they can share a single PCH file, beecause they use the same compiler option.
I even don't use the "-no-undefined and --enable-runtime-pseudo-reloc" as stated in the link page.

EDIT:
The current dll(plugin) framework of C::B is just like the one I described in Plugin structure of C::B.

ollydbg:
OK, I can use a same PCH for either dll or exe, I just create a simple "sdk.h" file

--- Code: ---#ifndef SDK_H
#define SDK_H
#include <stdio.h>
#include "example_dll.h"
#endif // SDK_H

--- End code ---
Then, I put the statement

--- Code: ---#include "sdk.h"
--- End code ---
at the every beginning of the cpp files. (you can remove the old #incude statements in the cpp file)

Here is the result:

--- Code: ---D:\test\test-dll>g++ -c -DNOPORT sdk.h

D:\test\test-dll>g++ -c -DNOPORT example_dll.cpp -Winvalid-pch -include sdk.h

D:\test\test-dll>g++ -shared -o example_dll.dll example_dll.o -Wl,--export-all-symbols

D:\test\test-dll>g++ -c -DNOPORT example_dll.cpp -Winvalid-pch -include sdk.h

D:\test\test-dll>g++ -o example_exe.exe example_exe.o -L. -lexample_dll

D:\test\test-dll>example_exe.exe
Hello World
666
CppFunc
MyClass.func()
D:\test\test-dll>dir
 Volume in drive D has no label.
 Volume Serial Number is 0006-7EF2

 Directory of D:\test\test-dll

2015-10-06  10:23    <DIR>          .
2015-10-06  10:23    <DIR>          ..
2015-09-27  09:52                89 env.bat
2015-10-06  10:16               260 example_dll.cpp
2015-10-06  10:23            41,773 example_dll.dll
2015-10-06  09:44               718 example_dll.h
2015-10-06  10:23             1,157 example_dll.o
2015-10-06  10:16               185 example_exe.cpp
2015-10-06  10:23            50,196 example_exe.exe
2015-10-06  09:48             3,197 example_exe.o
2015-10-06  10:17                91 sdk.h
2015-10-06  10:20         1,577,668 sdk.h.gch
              10 File(s)      1,675,334 bytes
               2 Dir(s)  23,734,190,080 bytes free

D:\test\test-dll>

--- End code ---

Look, one single pch file.  ;)


ollydbg:
Now, I did some test in codeblocks_wx30.cbp
1, I remove the "src\.objs30\include\sdk.h.gch", so the folder only contains "sdk_precomp.h.gch", note that the first one was create when we build the src target(codeblocks.exe), and the later one is generated when we build the sdk target(codeblocks.dll).

2, select the "sdk.h" from the project manager panel, and right click to open the "property" dialog, and uncheck the "compile file" option.

3, copy the build option from sdk to src, that is: remove the "BUILDING_PLUGIN", and add those:

--- Code: ---EXPORT_LIB
EXPORT_EVENTS
WXMAKINGDLL_SCI

--- End code ---

4, rebuild the target src(codeblocks.exe), and I see it build successfully, great! This means both the codeblocks.exe and codeblocks.dll now share the same pch file "sdk_precomp.h.gch".

I will see I can built any plugin dll later. :)


EDIT:
Good, with the same change to other C::B plugin target, I can also build them successfully, also the build C::B runs OK.

ollydbg:
Here is one issue I see that the icon shows badly in wx 3.0.2 based C::B compared with wx 2.8 based.
See the image show below(the left is wx 3.0.2 based)

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version