views:

604

answers:

11

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 ?

+3  A: 

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.

Ben S
+1, writing for linux and using mingw or cygwin seems to be easiest, expecially since things like pthreads are (relatively) portable now. Sockets are also easy to write cross platform due to openssl. You basically have to implement system-specific things in their own classes and write a makefile which excludes the relevant stuff from the build - but if you do it smartly and check the cross-platform libraries (pthreads/openssl are just two examples) you'll write very few system specific classes
laura
I won't downvote, but writing code for Linux and using Cygwin is not real cross-platform programming, it's just convenient for the programmer.
rpg
Also, bundling Cygwin with your application requires you to release your application under a GPL-compatible license, unless you have a commercial Cygwin license.
JesperE
Thanks for replying.However I don't think that's a real solution. Like i said before I want to use DirectX on windows and even though minGW or cinGW can do it. cl can do it better and also it makes my life easier. I rather focus on my code than spending ages resolving this kind of issue.
lollancf37
Xilinx uses this strategy for their FPGA synthesis tools. Everything is written for Linux (even the GUI) and it's packaged with a cygwin setup for Windows. The problem is that it's really blasted unstable on Windows, crashes frequently, and support for newer operating systems (i.e. Win 7) inevitably lags way behind because you have to wait for cygwin to support it before you can.While this works, it's not the best approach IMHO.
Bob Somers
Bob: that's not strictly true -- while Xilinx uses Cygwin for a lot of the EDK support stuff (in part because GCC is used for MicroBlaze), all the synthesis tools (XST, MAP, PAR, etc.) are native Windows applications built with VC++. GUIs like ProjNav are built on Qt.
mrkj
+8  A: 

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)

Cristian Adam
Hi,I think you are right. After I wrote that question I work harder on CMake and to be frank I don't even know why i went to boost build lol.Also thanks for the book, I think I'll go for it.Thanks for replying.
lollancf37
A: 

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.

T.E.D.
In this case it works fine, not in mine.Thanks for replying.
lollancf37
+3  A: 

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

rpg
Thanks for replying.Even though I like QT for this project I can't use it. But i didn't know about QT creator (it's been a while with QT).As I said above CMake is alright.
lollancf37
+1  A: 

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?

Vladimir Prus
Yes I was looking at boost.build. It's just that boost.build represent all the configurations files used by bjam to build soft that's why I mixed the two.Thanks for the info about people using it with VS but do you where I can have a look at that ?Cheers
lollancf37
I'd recommend that you ask on [email protected]. Be sure to describe your problem in detail.
Vladimir Prus
+1  A: 

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.

JesperE
I know you're right now, thanks ^^
lollancf37
+2  A: 

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.

Mathieu JVL
A: 

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.

StackedCrooked
A: 

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.

Stephen Newell
A: 

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.

OneOfOne
A: 

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

Void