Compiling errors with VS2015 64 bits Topic is solved

Do you have a question about makefiles, a compiler or IDE you are using and need to know how to set it up for wxWidgets or why it doesn't compile but other IDE's do ? Post your questions here.
Post Reply
edamiani
In need of some credit
In need of some credit
Posts: 4
Joined: Tue Jan 31, 2017 2:34 pm

Compiling errors with VS2015 64 bits

Post by edamiani »

Hi, I'm compiling wxWidgets using VS2015's nmake (64 bits). The library and its samples are compiling perfectly, but when I try to add them to my own project a couple of different issues arise.

I'm setting up my project using CMake, so these are basically the command lines I've added to it:

Code: Select all

set(wxWidgets_CONFIGURATION mswu)
set(wxWidgets_ROOT_DIR ${PROJECT_SOURCE_DIR}/Dependencies/wxWidgets)
set(wxWidgets_LIB_DIR ${PROJECT_SOURCE_DIR}/Dependencies/wxWidgets/lib/vc_lib)
find_package(wxWidgets COMPONENTS core base REQUIRED)
include_directories("${PROJECT_SOURCE_DIR}/Dependencies/wxWidgets/include")
I also added the library as a target link to one of my projects inside CMake, but I'm sure it's working fine.

The projects are generated correctly, but when I try to compile the project that is using wxWidgets, it says that setup.h is missing. I've made some digging in the makefile.vc file and found this line:

Code: Select all

SETUPHDIR = \
	$(LIBDIRNAME)\$(PORTNAME)$(WXUNIVNAME)$(WXUNICODEFLAG)$(WXDEBUGFLAG)
WXREGEX_CFLAGS = /M$(__RUNTIME_LIBS_10)$(__DEBUGRUNTIME) /DWIN32 \
	$(__DEBUGINFO) /Fd$(LIBDIRNAME)\wxregex$(WXUNICODEFLAG)$(WXDEBUGFLAG).pdb \
	$(____DEBUGRUNTIME) $(__OPTIMIZEFLAG) /D_CRT_SECURE_NO_DEPRECATE=1 \
	/D_CRT_NON_CONFORMING_SWPRINTFS=1 /D_SCL_SECURE_NO_WARNINGS=1 \
	$(__NO_VC_CRTDBG_p) /DNDEBUG /D_CRT_SECURE_NO_WARNINGS /I..\..\include \
	/I$(SETUPHDIR) /D__WXMSW__ $(__WXUNIV_DEFINE_p) $(__UNICODE_DEFINE_p) \
	$(CPPFLAGS) $(CFLAGS)
So I added this folder manually to CMake, to be more specific:

Code: Select all

include_directories("${PROJECT_SOURCE_DIR}/Dependencies/wxWidgets/lib/vc_lib/mswud")
But when I try to compile it I receive these error messages (plus a lot of security warning messages, which I omitted):

Code: Select all

1>------ Build started: Project: ZERO_CHECK, Configuration: Debug x64 ------
2>------ Build started: Project: TestWindowWxWidgets, Configuration: Debug x64 ------
2>  TestWindowWxWidgets.cpp
2>D:\GitHub\AnimaLite\Dependencies\wxWidgets\include\wx/msw/winundef.h(38): error C2664: 'HWND CreateDialogParamW(HINSTANCE,LPCWSTR,HWND,DLGPROC,LPARAM)': cannot convert argument 2 from 'LPCTSTR' to 'LPCWSTR'
2>  D:\GitHub\AnimaLite\Dependencies\wxWidgets\include\wx/msw/winundef.h(38): note: Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
2>D:\GitHub\AnimaLite\Dependencies\wxWidgets\include\wx/msw/winundef.h(69): error C2664: 'HFONT CreateFontW(int,int,int,int,int,DWORD,DWORD,DWORD,DWORD,DWORD,DWORD,DWORD,DWORD,LPCWSTR)': cannot convert argument 14 from 'LPCTSTR' to 'LPCWSTR'
2>  D:\GitHub\AnimaLite\Dependencies\wxWidgets\include\wx/msw/winundef.h(69): note: Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
2>D:\GitHub\AnimaLite\Dependencies\wxWidgets\include\wx/msw/winundef.h(95): error C2664: 'HWND CreateWindowExW(DWORD,LPCWSTR,LPCWSTR,DWORD,int,int,int,int,HWND,HMENU,HINSTANCE,LPVOID)': cannot convert argument 2 from 'LPCTSTR' to 'LPCWSTR'
2>  D:\GitHub\AnimaLite\Dependencies\wxWidgets\include\wx/msw/winundef.h(95): note: Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
2>D:\GitHub\AnimaLite\Dependencies\wxWidgets\include\wx/msw/winundef.h(111): error C2664: 'HMENU LoadMenuW(HINSTANCE,LPCWSTR)': cannot convert argument 2 from 'LPCTSTR' to 'LPCWSTR'
2>  D:\GitHub\AnimaLite\Dependencies\wxWidgets\include\wx/msw/winundef.h(111): note: Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
2>D:\GitHub\AnimaLite\Dependencies\wxWidgets\include\wx/msw/winundef.h(311): error C2664: 'HICON LoadIconW(HINSTANCE,LPCWSTR)': cannot convert argument 2 from 'LPCTSTR' to 'LPCWSTR'
2>  D:\GitHub\AnimaLite\Dependencies\wxWidgets\include\wx/msw/winundef.h(311): note: Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
2>D:\GitHub\AnimaLite\Dependencies\wxWidgets\include\wx/msw/winundef.h(324): error C2664: 'HBITMAP LoadBitmapW(HINSTANCE,LPCWSTR)': cannot convert argument 2 from 'LPCTSTR' to 'LPCWSTR'
2>  D:\GitHub\AnimaLite\Dependencies\wxWidgets\include\wx/msw/winundef.h(324): note: Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
2>D:\GitHub\AnimaLite\Dependencies\wxWidgets\include\wx/msw/private.h(807): error C2664: 'BOOL UnregisterClassA(LPCSTR,HINSTANCE)': cannot convert argument 1 from 'const wchar_t *' to 'LPCSTR'
2>  D:\GitHub\AnimaLite\Dependencies\wxWidgets\include\wx/msw/private.h(807): note: Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
2>D:\GitHub\AnimaLite\Dependencies\wxWidgets\include\wx/msw/private.h(886): error C2664: 'DWORD GetModuleFileNameA(HMODULE,LPSTR,DWORD)': cannot convert argument 2 from 'wxStringTypeBuffer<wxChar>' to 'LPSTR'
2>  D:\GitHub\AnimaLite\Dependencies\wxWidgets\include\wx/msw/private.h(886): note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
========== Build: 1 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
It seems to me that the library is being compiled against non-Unicode Windows headers, so is there something else that I should add to fix that?

By the way, I'm using the latest version from Github.


Thanks in advance,
Edgard
User avatar
doublemax
Moderator
Moderator
Posts: 19159
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Compiling errors with VS2015 64 bits

Post by doublemax »

Most likely this is caused by order of include files. In the source files where you use wxWidgets, try including all needed wxWidgets headers first, then all others. If that fails, try the other way round.
Use the source, Luke!
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4204
Joined: Sun Jan 03, 2010 5:45 pm

Re: Compiling errors with VS2015 64 bits

Post by PB »

I know very little about CMake, I created the CMakefile for wxAutoExcel mostly via googlefu and looking at CMakeFiles for other projects. Nevertheless, I was able to build wxAutoExcel library as well as its samples with MSVC 2015 in 64-bit mode without any problems.

The only wxWidget related stuff, other than setting some defines when needed (such as WXUSINGDLL), in that CMakeFile is:

Code: Select all

find_package(wxWidgets 3.1.0 COMPONENTS core base REQUIRED)
include( ${wxWidgets_USE_FILE} )
I certainly do not include the wxWidgets header folder manually. If you do that, I think you still need to put the configuration-specific folder before the main header folder, i.e., the include directories could be e.g. $(WXWIN)\lib\vc14_lib\mswu;$(WXWIN)\include for the static release build.

Of course I link the libraries with target_link_libraries(project ${wxWidgets_LIBRARIES}) and I make sure that In CMakeGUI the wxWidgets_LIB_DIR points to the folder where the wxWidgets libraries built in 64-bit mode reside.

Edit
I am not sure if I tested the 64-bit build with nmake or with the IDE only. I will try to do that tomorrow, not that it should make a difference IMO.
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4204
Joined: Sun Jan 03, 2010 5:45 pm

Re: Compiling errors with VS2015 64 bits

Post by PB »

FWIW, I just tried the to build the barest possible wxWidgets Windows application with CMake (3.7.2) and NMake (VC 2015) in 64-bit mode.

Source of the application

Code: Select all

#include <wx/wx.h>

class MyApp : public wxApp
{
public:	
	bool OnInit()
	{
        (new wxFrame(NULL, wxID_ANY, "Minimal"))->Show();
        return true;
	}
};
wxIMPLEMENT_APP(MyApp);
CMakeLists.txt - the system environment variable WXWIN points to the root of the wxWidgets folder so CMake can find wxWidgets automatically but I needed to change the wxWidgets_LIB_DIR, as my 64-bit VC2015 wxWidgets libs are in vc14_x64_lib instead of vc14_lib.

Code: Select all

cmake_minimum_required(VERSION 3.0)

project(minimal)

find_package(wxWidgets 3.0 COMPONENTS core base REQUIRED)
include(${wxWidgets_USE_FILE})

add_executable(minimal WIN32 minimal.cpp)
target_link_libraries(minimal ${wxWidgets_LIBRARIES})
I could build it in 64-bit mode both with the IDE and NMake. I setup the environment for NMmake both when building wxWidgets and the application) with

Code: Select all

call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\x86_amd64\vcvarsx86_amd64.bat"
Attachments
CMake minimal.zip
(952 Bytes) Downloaded 60 times
edamiani
In need of some credit
In need of some credit
Posts: 4
Joined: Tue Jan 31, 2017 2:34 pm

Re: Compiling errors with VS2015 64 bits

Post by edamiani »

Hey guys, thanks a lot for the answers!

Indeed, the main problem was the include order, so reinserting the command "include(${wxWidgets_USE_FILE})" at the very top of the CMake file and removing the include_directories command did the trick. :D


Thanks!
Edgard
Post Reply