microsoft / VSLinux

VS extension for C++ Linux development
205 stars 34 forks source link

Does adding the reference to a project add this project to the linker input? #363

Closed MichaelKv closed 2 years ago

MichaelKv commented 5 years ago

Hello. Given the projects A and B where A depends on B and requires B as the linker input if I add B as the reference for A it will automatically link B to A for Windows builds. This approach does not work for Linux builds and I have to set B as the linker input for A manually in Library Dependencies and Additional Library Directories. Is it the supposed/intentional behavior or a bug?

Thank you.

yuehuang010 commented 5 years ago

@MichaelKv , using Project to Project reference should work. Which version of VS are you using?
You shouldn't need to do "Path Math" between projects. The Project Reference should take care of that for you. To share include files between projects, use the "Public Project Include Path" variable under C/C++. The build will handle the path translation for you.

If you are still having trouble please share your sample. Thanks.

MichaelKv commented 5 years ago

Well, the example is trivial but as you wish. Here is the concrete example that does not work for me in VS2017 or VS2019. Please, see the attached archive. BTW, you might probably ask the VS guys to add -fPIC option automatically. The solution attached fails to compile with the following error message: 1>Starting remote build 1>Compiling sources: 1>a.cpp 1>Linking objects 1>C:\MKS\tmp\Solution1\Projects\A....\obj\x64\Debug\a.o : error : In function main': 1>C:\MKS\tmp\Solution1\src\A\a.cpp(4): error : undefined reference tof()' 1>collect2 : error : ld returned 1 exit status 1>Done building project "A.vcxproj" -- FAILED.

Now you can add B manually to Library Dependencies and Additional Library Directories. Please, note that you will not be able to add the directory as $(OutDir) – it will not work too. I use the full Unix path. It compiles and links now.

2>Validating architecture 2>Starting remote build 2>Compiling sources: 2>a.cpp 2>Linking objects 2>A.vcxproj -> C:\MKS\tmp\Solution1\bin\x64\Debug\A.out 2>Done building project "A.vcxproj".

I am not sure the archive with the example solution was properly attached. The GitHub does not work with IE 11 normally anymore and my LTSB Windows does not allow me to use Edge.

MichaelKv commented 5 years ago

I do not see my attachment. If you need it please, feel free to ask me to resend it by email.

yuehuang010 commented 5 years ago

I can't see your attached sample. If you can't upload them here, the you can email to your sample to VC++ Linux Support vcpplinux-support@microsoft.com.

MichaelKv commented 5 years ago

Done. Please, see Solution1.zip.

MichaelKv commented 5 years ago

Only x64 Debug configuration was configured.

benmcmorran commented 2 years ago

This issue is being closed because we are no longer tracking VS Linux issues on GitHub. If the issue still reproduces, bugs and new suggestions should be reported on the Developer Community forum. It is centralized, better equipped for group voting, and has more visibility.