lollancf37
lollancf37

Reputation: 1125

Cross-platform development?

I am looking for a solution which would allow me to code for Linux and Windows using C++.

On Windows I use Visual Studio (I tried other stuff on Windows but I work with DirectX and as far as I know, it's the best solution).

On Linux I use NetBeans (which I like very much).

My problem is that I want the project be independent of Visual Studio and NetBeans.

For a while I thought that CMake was the solution, however the learning process is too important, I rather spend my time coding than learning all the tricks with CMake. So I settled for Boost.Jam. It worked fine on Linux but sucked with Visual Studio.

I created a small Hello World program, on Windows. I created a Visual Studio Makefile project and while it's compiling and linking correctly. I can run the executable but not from Visual Studio, which can't find the executable (no matter what I do). I can't debug either. Also I can't see the compilation error message when I get one. All I can see from Visual Studio is that there is a makefile action in progress and that there is a mistake about it (even though the program is created and run fine).

I've been browsing the Boost.Jam documentation for a while but let's face it, it's pretty poor (no wonder not a lot of people heard of it) or I'm pretty not suited for the job (meaning stupid lol but yet why so few heard of it).

I have three questions:

I'd like to know if somebody heard of a project which use Boost.Jam with visual studio? If yes can I have a look at it ?

Is there a tool out there with real Visual Studio integration?

How many people think that learning to use CMake (correctly) cost a lot of time? Any tricks to speed up?

Upvotes: 1

Views: 1593

Answers (11)

Void - Othman
Void - Othman

Reputation: 3481

MPC, "the Makefile, Project, and Workspace Creator", is another tool that could be of use to you.

Upvotes: 1

OneOfOne
OneOfOne

Reputation: 99331

I don't know how complex you wanna get, I use mingw-4.4.2 + cmake on linux to compile my Qt4 apps for windows, and NSIS on wine to create the setup files. Basicly I hacked my CMakeLists.txt to use mingw when I pass -DWin32=1. here's the relevent part :

if(WIN32) 
    SET(CMAKE_BUILD_TYPE "Release") #force release for win32, no motive to debug on win32

    SET(CMAKE_CXX_FLAGS_RELEASE  "-march=pentium4 -mtune=pentium4 -mwindows -DNDEBUG -mno-align-stringops -minline-stringops-dynamically -fno-ident -freorder-blocks-and-partition -finline-limit=700 -mfpmath=sse  -ftree-loop-distribution -floop-block -floop-interchange -floop-strip-mine -findirect-inlining -ftree-switch-conversion ${BASE_CXX_FLAGS}")

    SET(WIN32_BASE /home/win32-devel)
    SET(QT_LIB ${WIN32_BASE}/qt-win-opensource-src-4.5.3/lib/)

    SET(CMAKE_CXX_COMPILER i686-pc-mingw32-g++)
    SET(CMAKE_AR i686-pc-mingw32-ar)
    SET(CMAKE_RANLIB  i686-pc-mingw32-ranlib)
    SET(CMAKE_LINKER i686-pc-mingw32-ld)

    ADD_CUSTOM_COMMAND( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/app_icon.o
                        COMMAND i686-pc-mingw32-windres
                            -I${CMAKE_CURRENT_SOURCE_DIR}
                            -o${CMAKE_CURRENT_BINARY_DIR}/app_icon.o
                            -i${CMAKE_CURRENT_SOURCE_DIR}/icons/win32_icon.rc
                        )

    SET(OPENSSL_LIBRARIES  ${WIN32_BASE}/openssl-0.9.8l/libeay32.dll;${WIN32_BASE}/openssl-0.9.8l/libssl32.dll)
    SET(QT_LIBRARIES  ${QT_LIB}QtCore4.dll;${QT_LIB}/QtGui4.dll)
    SET(CMAKE_EXECUTABLE_SUFFIX ".exe")

    include_directories(${CMAKE_CURRENT_BINARY_DIR} ${QT_LIB}../include ${WIN32_BASE}/openssl-0.9.8l/include)
    message("Building For   : Win32")
else()
    include_directories(${CMAKE_CURRENT_BINARY_DIR} ${QT_INCLUDES} ${OPENSSL_INCLUDE_DIR})
    message("Building For   : Linux")
endif()
SET(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "-Wl,--no-undefined -static-libgcc -Wl,-O1 -Wl,--as-needed -Wl,--sort-common -s")

edit: Forgot to mention that actual development is done using KDevelop 4.

Upvotes: 1

Stephen Newell
Stephen Newell

Reputation: 7863

The only non-trivial thing about using CMake for cross-compilation is writing the toolchain information: CMake figures out the rest. See http://www.cmake.org/Wiki/CMake_Cross_Compiling#The_toolchain_file for more information.

Upvotes: 1

StackedCrooked
StackedCrooked

Reputation: 35515

I've seen a CMake demo at Fosdem a few months ago and it looked pretty impressive. I think it the time spent learning it may be worthwhile.

On the other hand, it is my personal experience that maintaining separate project files per platform is a perfectly acceptable way of doing things.

Upvotes: 1

Mathieu JVL
Mathieu JVL

Reputation: 345

I'd recommend CMake as well. It's a bit scary at first but you ease into it progressively. It's still rather easy for a beginner to write cross-platform scripts, even if they are not pretty or optimal as an expert would do. Integration with CppUnit (for unit tests) and Hudson (build mgt) made it possible to configure a Continuous Integration framework in no time.

Upvotes: 3

JesperE
JesperE

Reputation: 64424

I don't know much about NetBeans, but if you want to develop for both Windows and Linux and use Visual Studio on Windows, then CMake is the only sane choice, really. I've used it for several years now, and I cannot begin to guess how much time it has saved me maintaining makefiles and project files.

Upvotes: 2

Vladimir Prus
Vladimir Prus

Reputation: 4650

Are you sure you're looking at the right documentation? You have said "Boost.Jam", so chances are high you are looking at wrong thing. Please visit Boost.Build documentation

I am positively sure that many people used Boost.Build inside Visual Studio without problems. Can you try running the program on the command line -- maybe there's some error message that Visual Studio decides not to show?

Upvotes: 3

rpg
rpg

Reputation: 7787

Qt and Qt Creator look like a good solution to your problem. qmake can generate vcproj files and native Linux makefiles.

Upvotes: 5

T.E.D.
T.E.D.

Reputation: 44804

Upvote for Ben. We have a major vendor that did a Windows port of their old Unix code for commodity hardware access, and that's exactly what they did.

Emacs works fine on both platforms, as does GNU make. If you need a GUI, I'd use GTK+ with MinGW/msys rather than Cygnus and an X port.

Upvotes: 1

Cristian Adam
Cristian Adam

Reputation: 4834

You should take the time to learn CMake and to speed up the learning process buy/read "Mastering CMake 4th Edition"

If you have problems you should use the CMake mailing list, which is active (August 2009 had ~600 messages)

Upvotes: 12

Ben S
Ben S

Reputation: 69382

If I were to code in C++ for Windows and linux I'd code for linux, and bundle the application with a minimal cygwin setup.

Upvotes: 4

Related Questions