Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 331
  • Last Modified:

vc++ project to linux

Hi,

I wrote a decently sized set of applications under win32 using vc++ 2005. None of the applications are GUIs, they're all just plain old console applications. I also made sure to wrap all win32 system calls in a library like:

void HelperLibrary::CreateProcess()
{
    #ifdef WIN32
         // .. call win api function to create a process.
    #else
         // .. linux equivalent
    #endif
}

yeah so i took special care to do all of that.

I put all my source code into subversion so it's all source controlled. I was hoping I could stick the same exact files onto a linux system and compile the project as is. But what will happen with all the vc++ specific files like the .sln file etc? How would I even begin compiling these projects under linux - i'd have to bring them all into some editor and tell each project whether it is a static library or an executable, etc.

Where do I start?

Thanks
0
DJ_AM_Juicebox
Asked:
DJ_AM_Juicebox
  • 2
  • 2
  • 2
  • +2
2 Solutions
 
jkrCommented:
>>Where do I start?

Here: http://www.hsrl.rutgers.edu/ug/make_help.html ("How to write a Makefile")

Then, you might want to continue at http://mrbook.org/tutorials/make/ ("Makefiles"), which iws a nice and IMO effective tutorial for the first steps. Then, delve into the depths of http://www.eng.hawaii.edu/Tutor/Make/ ("Make - a tutorial")
0
 
ikeworkCommented:
just ignore the vc-specific-files and leave them where they are.
you can also use an IDE on linux, there are some, like kDevelop. it generates make-files and installers for you, like VC++ does.

http://www.kdevelop.org/index.html?filename=main.html&set_lang=en

0
 
sjith2000Commented:
Yes. As jkr and ikework suggests, you can forget the .sln and other VC++ specif files.I Linux MakeFile is
everything.You only have to keep your .cpp files and Makefile.

As jkr suggests you can first go through the Make Tutorial.Initially writing a Makefile will be very difficult be cause even the spaces between the charcters and commands inside a Makefile are very difficult.

So to do it easily, programmers download some very simple makefiles and analyse that and try adding new commands to that.That is an easy way to start off with your own make file once you are done with the tutorial.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
sjith2000Commented:
Sorry just correcting my previous sentence.

As jkr suggests you can first go through the Make Tutorial.Initially writing a Makefile will be very difficult because even the spaces between the charcters and commands inside a Makefile are very important when you write a make file.

0
 
itsmeandnobodyelseCommented:
>>>> will happen with all the vc++ specific files like the .sln file etc?

The .sln file is a minor file which has a reference to the project file (.vcproj) and some dependencies if more than one project is in the solution. The file which is more important is the .vcproj file as it has the same purpose as a LINUX Makefile.

If you name your makefile 'Makefile' and put it into your LINUX project folder, you simply can type 'make' in order to invoke the makefile. If your project has a few files only and not much libraries, you may look for *any* makefile coming with a tutorial or a sample project, copy it to the project folder where the sources are, and replace the target (file)names and folders in the makefile. I always used to edit in the Visual Studio and transfered to the UNIX after but that may be simply cause I didn't know a suitable editor on the UNIX side. Be aware that LINUX is case sensitive. You best make all filenames (in include statements as well!) lower case *prior* to moving the files to UNIX. I always tried to have *one* source only and make changes only at one system.

Regards, Alex
0
 
DJ_AM_JuiceboxAuthor Commented:
Ok I think what I'll do (since the makefiles look pretty tedious) is get kdevelop on the linux machine and add all the source files to it in a linux project, then add that to source control as well. As long as vc++ ignores the kdevelop files when building on windows, and kdevelop ignores the vc++ files when building for linux, it should be ok right?

Thanks
0
 
itsmeandnobodyelseCommented:
>>>> it should be ok right?
yes, LINUX doesn't care for .vcproj and VS doesn't care for Makefile.

>>>> since the makefiles look pretty tedious
it isn't so difficult if you start with a little test project and examine the makefile. The one you should know is that a makefile goes for 'targets', e. g.

// excerpt of a makefile

# rule(s)
# creates object from source.
.c.o:
      $(CC) $(CFLAGS) $<

# target(s), first target is default target
wmvt: $(OBJS)
      $(CC) $(CSFLAGS) -o wmvt.so $(EXPCOPT) $(LFLAGS) $(OBJS)

Here you have two targets. The '.c.o' and the 'wmvt' target. The end of a target is the next empty line. It works like a break; in a switch statements.

After a target there can be specified new targets, e. g. the $(OBJS) after wmvt:

The $()  evaluates a macro. In OBJS all objectfiles of my project 'wmvt' were listed. If my current target is 'wmvt' the compiler checks if any of the object files is not up-to-date. It does that by applying the above 'rule'  .c.o  which says that the 'source' for each object file (.o) is the .c file with the same name. If any of the .c files is younger than the corresponding .o file the target will be applied what means that the

    $(CC) $(CFLAGS) $<

will be applied for the current objectfile (specified by $<). CC and CFLAGS are macros defined at top of the makefile. CC is the compiler command and CFLAGS the compiler switches and options.

After each object that was not upto-date was built the make would finish the wmvt macro by invoking the

   $(CC) $(CSFLAGS) -o wmvt.so $(EXPCOPT) $(LFLAGS) $(OBJS)

what is the linker part of the compiler (in my sample it creates a 'shared object' what is a dll at UNIX using an export list and the list of object files and some special compiler flags in CSFLAGS).

Regards, Alex
0
 
DJ_AM_JuiceboxAuthor Commented:
@itsmeandnobodyelse:

I went through the makefile tutorial, I mean it's not horrible, looks easy for smallish projects - but eventually I want the whole project to be developed only for linux anyway. So I'd like to have some IDE to start developing with on linux. If I have KDE solution files (which i assume are just the equivelnt to vc++ more or less) i guess that setup will work fine?

Thanks
0
 
jkrCommented:
Well, Makefiles are pretty much the standard in the UN*X world, even for large projects - e.g. the Linux kernel comes with a Makefile. On the Windows side, VC++ ships with NMAKE, which is pretty much conformant to the BSD 'make' on the UN*X side. Yet I'd also not try to mix the build file for both platforms. NMAKE support has been reduced by MS during ech recent release of VC++.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now