-1

I've got this simplified folders structure for c++ project named project_name.

project_name
    -build
    -headers
    -sources 
    -resources

If I do cl /EHsc /W4 sources/source1.cpp sources/source2.cpp /link /out:project_name ... it creates build files in current directory only which is project_name, resulting this:

project_name
    -build
    -headers
    -sources 
    -resources
     project_name.exe         
     source1.obj
     source2.obj
     etc

What I want is to specify the folder where all the build files have to be placed, in my case in a build folder.

What options are needed for cl or link to do that that from project_name directory ?

mvidelgauz
  • 2,176
  • 1
  • 16
  • 23
ampawd
  • 968
  • 8
  • 26
  • Did you read [this](https://msdn.microsoft.com/en-us/library/f35ctcxw.aspx) and especially [this](https://msdn.microsoft.com/en-us/library/610ecb4h.aspx) and [this](https://msdn.microsoft.com/en-us/library/y0zzbyt4.aspx) arcticles? – mvidelgauz Jun 25 '16 at 12:14
  • @mvidelgauz what's the reason for downvoting my question ?? Yes I did read those articles – ampawd Jun 25 '16 at 12:19
  • The reason downvoting in this case is _"question does not show any research effort"_. I think those articles (found in few seconds) clearly answer your question – mvidelgauz Jun 25 '16 at 12:23
  • @mvidelgauz you are wroung, if they answer my question I woudn't have posted it here on so. The research effort can be achieved by thinking of a solution to my problem – ampawd Jun 25 '16 at 12:28
  • You specified output for linker only, but not for `cl` - that's why .obj files are in root. Read [this](https://msdn.microsoft.com/en-us/library/yb8e9b8y.aspx). And for other output files read [this](https://msdn.microsoft.com/en-us/library/f1cb223a.aspx) – mvidelgauz Jun 25 '16 at 12:29
  • @mvidelgauz That is the *actual* answer to this question; you should post it as one. – Cody Gray - on strike Jun 25 '16 at 13:15
  • @CodyGray The answer given by yngum is better (that's me who upvoted it) if we think about ***actual solution for the problem***. My answer is more formal and more to explain OP why I downvoted this question – mvidelgauz Jun 25 '16 at 14:30

1 Answers1

1

Place a .bat file in your project directory and use that to build your project.

pushd %~dp0/build
cl %~dp0/sources/source1.cpp %~dp0/sources/source2.cpp
popd

%~dp0 automatically expands to full path of your project directory so you can execute this .bat file from anywhere.

yngccc
  • 5,594
  • 2
  • 23
  • 33