4

why x86 folder exist in obj folder in c Sharp project file?

My project file structure is

ProjectOne
----------Bin
--------------Debug
--------------Release
----------Obj
--------------x86 //Why this?
-------------------Debug
-------------------Release
----- My source files.

Why my file current Directory is bin\debug, not projectOne (where my source file exists)?

John Saunders
  • 160,644
  • 26
  • 247
  • 397
PawanS
  • 7,033
  • 14
  • 43
  • 71

4 Answers4

6

When executing, the current directory will default to wherever the executable is - which will be in your bin/debug directory.

You can set where you want it to run from when you start it in Visual Studio though (in the project properties - if you need more details, please say exactly which version/edition of VS you're using).

As for the contents of the obj directory - you can pretty much ignore the whole directory. It's full of intermediate files that Visual Studio builds and then consumes - but you almost never need to use any files from there directly.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • oh!! you mean current directory would be, where my exe file exist... I want to use a xml file in projectOne dir, the I'd go 2 up folder, ../../xmlfile – PawanS Dec 06 '10 at 07:32
  • 2
    If you right click Properties on the xml file in Visual Studio, you can set the "Copy to Output Directory" to "Copy if newer", and it will be copied to the bin/Debug directory when you build, and will make deployment of your app easier. – cspolton Dec 06 '10 at 07:37
  • @spolto... wow!! thanx for this tip. Anyhow I resolved my problem but u gave really nice tip. – PawanS Dec 06 '10 at 07:40
  • @Jon Skeet hey sir I've one question : Is object(.obj) file created during compilation or execution in c# ? – Vikas Verma Dec 07 '14 at 16:36
  • @VikasVerma: Compilation time - but they're really just for the compiler. You don't need to ship them anywhere. – Jon Skeet Dec 07 '14 at 16:42
  • @JonSkeet can we see this file after compilation ? – Vikas Verma Dec 07 '14 at 16:46
  • @VikasVerma: Yes, look in the obj directory. But they're not *useful* as far as I'm aware. – Jon Skeet Dec 07 '14 at 16:48
  • @JonSkeet yeah sir I've looked there but I've not found any .obj related file – Vikas Verma Dec 07 '14 at 16:52
  • 1
    @VikasVerma: Given that it's effectively a compiler-specific implementation detail, it's possible that newer compilers don't use this. For example, for C# code, Roslyn in VS2015 is a completely different compiler to the previous versions. – Jon Skeet Dec 07 '14 at 17:04
  • "you never need to use any files from there directly" - not true; I'm using a Crypto Obfuscator project to directly reference these files and in-turn be used in the Post-Build Script to overwrite the resultant binaries with obfuscated ones. Unfortunately the x86/x64 sub-directories in the obj folder have now complicated the build process for the project in question. – Matt Arnold May 31 '19 at 15:29
  • 1
    @MattArnold: Fixed to "almost never" - I suspect it's about 1 in 100,000 developers need to care about the obj directory... – Jon Skeet Jun 01 '19 at 08:58
1

The x86 folder refers to the target platform for your build in your build configuration manager. It allows you to build 32 bit applications on a 64 bit OS. As Cody and Jon say you can ignore the obj directory.

cspolton
  • 4,495
  • 4
  • 26
  • 34
0

The bin folder contains your application's binary files (that is, your executables). It is subdivided into two (or more) folders—typically Debug and Release. These correspond to your build configurations. When your project is compiled, the executable files are placed into one of these folders, depending on which type of build you conducted. If you want to run your executable outside of the development environment, you can click on the ".exe" file you find in one of these folders.

If you wish, you can change where Visual Studio outputs your executable files during a compile using your project's Properties window.

The obj directory contains intermediate (or object) files that Visual Studio builds when compiling your application. It's not really something you ever need to worry about or use the files from.

Finally, your source files are kept in the root directory, as displayed in your Solution Explorer window. You manage the locations of these files yourself; they are not managed by Visual Studio.

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
0

Object files (the files stored in Obj) are compiled binary files that haven't been linked. Think of it as fragments of the final executable that will later be combined to make your executable.

When compiling your source code each source file will loosely be compiled to one object file. Why? No reason*, just how your particular compiler was written. There are other compilers in other languages that does not do this but instead compile everything into a single large binary in one step. But the people who wrote your compiler decided to first compile to separate object files.

Now, you can imagine that if each source file generate one object file then every time you compile code your source directory will end up being messy and be filled with lots of .obj files (and indeed a lot of C compilers traditionally did this). Over time, developers working on large projects started to write compile script or configure their projects to collect all .obj files in a single directory to make the source directory less messy.

The people who wrote your compiler obviously liked the idea of a separate Obj directory so they made it the default configuration of projects. As for why there is an x86 subdirectory that's because your compiler also supports other CPUs like ARM (for Android, Win Phone 7 and iPhone) and also to differentiate between 32bit and 64bit.


* note: There are actually some very good reasons to do this including making the compiler code more modular and to support incremental compilation but the fact that some people can do all that without generating separate obj files mean that it is mostly a design decision by the developers of the compiler more than it being a necessity.

slebetman
  • 109,858
  • 19
  • 140
  • 171
  • can you give me a valid source where it is written that object file is created during execution or compilation process ? – Vikas Verma Dec 07 '14 at 16:31
  • @VikasVerma: I don't have a handy reference right now I guess I can google it but if I'm going to google it I'd might as well tell you to google it. Just delete all the .obj files and compile your source. You'll see them generated. That means they're generated by the compilation process. – slebetman Dec 07 '14 at 19:19
  • I've looked obj folder to see .obj files but I haven't found any .obj related files after compilation. – Vikas Verma Dec 07 '14 at 19:49