Thomas Covenant

VS newbie here.

I downloaded GALib, a C++ implementation of a genetic algorithm framework, and compiled it both as a static and a dynamic library. Now I want to test my libraries with example programs supplied by GALib.

GALib comes with demo programs whose source code resides in the same directory. Since it's developed on Unix, the libraries are made via Makefile, which has no trouble with creating multiple programs. I'm very familiar with that. I'm less familiar with VS's paradigm of solutions and projects, although I think I'm starting to get a handle on it.

My "Examples" project (basically an import of the "examples" directory in the GALib distribution) has a series of files:

example1.cpp
example2.cpp
example3.cpp
...

each one is its own GA which solves some optimization problem that illustrates the different capabilities of GALib. Ideally, I would like to simply press the "Build Examples" button and have each one compile as a standalone application that compiles against the GALib static library, galib.lib.

I don't know how to do this. How can one compile a series of executables from a series of cpp files in the same project

Also, these programs were meant to be run in an xterm. How can I run an individual program from within VS and have the terminal "stay around" so that I can take a look at the output once the program is finished I assume the terminal normally goes away when the program ends.

Thanks!


Re: Visual C++ General Project with Multiple Targets

Sara Sings

I just made a separate project for example1.cpp, compiling against the static library. It works! :-) The process is semi-involved:

0. Create an empty project
1. Add a source file.
2. Add a define.
3. Set a dependence.
4. Add a library directory.
5. Build.

However, there are nearly 30 different example programs which are waiting to be made. I don't want to have to do those 5 steps 30 times, especially since the configuration for each of the 30 projects is exactly the same (they all share the same #define, dependency, and library directory).

Ideally, I'd like to have a project that simply builds all of them together in one project.

Barring that, is there some way to clone a project All that really needs to be done is the source code filename needs to change. Other than that, the projects would be all clones of each other.

And if I can't have that, is there a way to set the #define and library directory at the solution level and have it inherited by all the projects

I know it must be do-able. I'm not asking for anything outrageous from the IDE.

Thanks!




Re: Visual C++ General Project with Multiple Targets

Simple Samples

You are asking about project creation, which is done once for each program. You are also asking building them, which is normally not a one-time thing.

If each project is in one solution, then VS will (try to) build all prjects when the solution is built.

I know you have many other questions but I hope this little bit helps.

Theoretically there are ways to automate what you are doing but I think the results would not justify the investment.






Re: Visual C++ General Project with Multiple Targets

Sara Sings

Hi Sam,

Just to make sure I understand. I download a C++ library that comes with 30 programs that demonstrate the library's features. All the programs come in the same directory called "example_programs".

The Unix programmer types "make" and he's done.

The VS user creates 30 different projects "from existing code", sets any #defines, sets dependencies, etc.

The thing is, we're talking about the difference between 2 seconds and 2 hours. Are there add-on tools that automate building a project from a directory full of cpp files

Thanks!
Pete




Re: Visual C++ General Project with Multiple Targets

Simple Samples

Sara Sings wrote:
Hi Sam,

Just to make sure I understand. I download a C++ library that comes with 30 programs that demonstrate the library's features. All the programs come in the same directory called "example_programs".

The Unix programmer types "make" and he's done.

That is incorrect. You either are missing something or typing make would not work for Unix either.

Note that Visual Studio has a "wizard" thing for creating projects from existing code.

Do you understand how the compiler knows what to compile and how to compile when make is used to compile I get the impression you are not familiar with the way make works. Are you familiar with makefiles I get the impression you are not. If there is not a makefile then it would likely be nore work in the Unix environment to create a makefile for all the programs. If there is a makefile then you can use it for Visual Studio also. Instead of learning about things like that, you are wasting time complaining.






Re: Visual C++ General Project with Multiple Targets

Sara Sings

Hi Sam,

I use make exclusively. For example, suppose someone handed me a directory full of one-file programs and told me to compile them quickly. This would be my minimalistic makefile that I'd write to get the job done:

Code Block

TARGETS = $(patsubst %.c, %, $(wildcard *.c))


all: $(TARGETS)

clean:
$(RM) *.o $(TARGETS)


and then I'd type "make". Of couse, I could pass compiler flags (CFLAGS), linker flags (LDLIBS), preprocessor flags (CPPFLAGS), etc.


I'm now working with Visual Studio. The only way I know how to do the same thing is to create a separate project for each program (each element of $(TARGETS) would now have its own project).

Is there an alternative to creating 30 projects I don't mind reading and learning a new topic. I actually really like the Visual Studio a whole lot.

I apologize if it seems like I'm complaining. That certainly wasn't intentional. But there has to be a faster way to compile a bunch of programs than creating a new file for each one, importing a single .cpp and .h file, setting a dependency, creating a global define, etc.

Are you saying I can write a makefile for visual studio That would be perfect.




Re: Visual C++ General Project with Multiple Targets

Simple Samples

VS has a makefile tool called nmake. You can use a makefile from the command line by executing nmake. Look in the documentation for it. One important detail is that you need to have the environment variables set for the path and other things. I think the VS menu has an item for executing a command line with everything set. I assume you can figure out how to customize the makefile to use whatever header and/or library directories that the programs require specific to them.

You can also create a makefile project that executes nmake semi-interactively. There is not much advantage using that compared to a command line but it is a little more convenient. Assuming the programs will be compiled only once and since you are familiar with use of the command-line (shell) way of doing things you probably don't need a project; you probably want to simply execute nmake for the makefile.






Re: Visual C++ General Project with Multiple Targets

Sara Sings

Super! Thanks so much!