Author Topic: Porting code - Windows to Linux  (Read 2027 times)

Offline Thunderchook

  • Multiple posting newcomer
  • *
  • Posts: 11
Porting code - Windows to Linux
« on: September 28, 2021, 11:31:58 am »
Hi,

I've been working on my C++ skills for quite some time.
Thus, I've moved from Windows to Linux, back to Windows and back to Linux again.

I have some code that I've written in one, and then moved over to the other.

The code is in the original files and same directory structure as before.
However, when I try to compile up this code, I get a laundry list of errors, none of which pertains to my actual code.
If I copy the raw code back into files of the same name under the new operating system, it compiles up just fine.

So, my question is: What must I do with my code to successfully port it over to a new operating system?

I'm currently trying to compile under Ubuntu 21.04.
The version of Code::Blocks I am using is: 20.03

Many thanks.



Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 837
Re: Porting code - Windows to Linux
« Reply #1 on: September 28, 2021, 12:53:26 pm »
Quote
I get a laundry list of errors

Can you post some of them (in code tags)?

Offline Thunderchook

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: Porting code - Windows to Linux
« Reply #2 on: September 28, 2021, 02:36:13 pm »
It just occurred to me that there are many, many path references to the old location from when it was on a Windows machine.
Is there a file or setting that I must clear to make it re-parse and pick up all the new locations?



||=== Build: Debug in Bignumbers (compiler: GNU GCC Compiler) ===|
/usr/bin/ld: obj/Debug/cbit.o||in function `Cbit::Cbit()':|
C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/cbit.cpp|3|undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string()'|
/usr/bin/ld: C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/cbit.cpp|5|undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator=(char const*)'|
/usr/bin/ld: C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/cbit.cpp|3|undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'|
/usr/bin/ld: C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/cbit.cpp|3|undefined reference to `_Unwind_Resume'|
/usr/bin/ld: obj/Debug/cbit.o||in function `Cbit::~Cbit()':|
C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/cbit.cpp|18|undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'|
/usr/bin/ld: obj/Debug/cbit.o||in function `Cbit::getDate[abi:cxx11]() const':|
C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/cbit.cpp|27|undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'|
/usr/bin/ld: obj/Debug/cbit.o||in function `Cbit::setDate(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)':|
C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/cbit.cpp|75|undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator=(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'|
C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/main.cpp|10|undefined reference to `__main'|
/usr/bin/ld: obj/Debug/main.o||in function `main':|
C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/main.cpp|12|undefined reference to `std::allocator<char>::allocator()'|
/usr/bin/ld: C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/main.cpp|12|undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)'|
/usr/bin/ld: C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/main.cpp|12|undefined reference to `std::allocator<char>::~allocator()'|
/usr/bin/ld: C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/main.cpp|13|undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'|
/usr/bin/ld: C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/main.cpp|13|undefined reference to `std::ostream::operator<<(std::ostream& (*)(std::ostream&))'|
/usr/bin/ld: C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/main.cpp|14|undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'|
/usr/bin/ld: C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/main.cpp|15|undefined reference to `std::basic_istream<char, std::char_traits<char> >& std::operator>><char, std::char_traits<char>, std::allocator<char> >(std::basic_istream<char, std::char_traits<char> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)'|
/usr/bin/ld: C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/main.cpp|18|undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'|
/usr/bin/ld: C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/main.cpp|18|undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'|
/usr/bin/ld: C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/main.cpp|22|undefined reference to `std::ostream::operator<<(std::ostream& (*)(std::ostream&))'|
/usr/bin/ld: C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/main.cpp|22|undefined reference to `std::ostream::operator<<(std::ostream& (*)(std::ostream&))'|
/usr/bin/ld: C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/main.cpp|22|undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'|
/usr/bin/ld: C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/main.cpp|22|undefined reference to `std::ostream::operator<<(std::ostream& (*)(std::ostream&))'|
/usr/bin/ld: C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/main.cpp|22|undefined reference to `std::ostream::operator<<(std::ostream& (*)(std::ostream&))'|
/usr/bin/ld: C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/main.cpp|22|undefined reference to `std::ostream::operator<<(std::ostream& (*)(std::ostream&))'|
/usr/bin/ld: C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/main.cpp|12|undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'|
/usr/bin/ld: C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/main.cpp|25|undefined reference to `std::allocator<char>::~allocator()'|
/usr/bin/ld: C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/main.cpp|25|undefined reference to `_Unwind_Resume'|
/usr/bin/ld: C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/main.cpp|18|undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'|
/usr/bin/ld: C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/main.cpp|12|undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'|
/usr/bin/ld: C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/main.cpp|12|undefined reference to `_Unwind_Resume'|
C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/C:/Program Files/CodeBlocks/MinGW/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/iostream|74|undefined reference to `std::ios_base::Init::~Init()'|
C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/C:/Program Files/CodeBlocks/MinGW/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/iostream|74|undefined reference to `std::ios_base::Init::Init()'|
/usr/bin/ld: obj/Debug/vecpart.o||in function `VecBit::readfile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)':|
C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/vecpart.cpp|25|undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string()'|
/usr/bin/ld: C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/vecpart.cpp|35|undefined reference to `std::basic_ifstream<char, std::char_traits<char> >::basic_ifstream()'|
/usr/bin/ld: C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/vecpart.cpp|36|undefined reference to `std::basic_ifstream<char, std::char_traits<char> >::open(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::_Ios_Openmode)'|
/usr/bin/ld: C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/vecpart.cpp|40|undefined reference to `std::basic_ios<char, std::char_traits<char> >::fail() const'|
/usr/bin/ld: C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/vecpart.cpp|42|undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'|
/usr/bin/ld: C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/vecpart.cpp|42|undefined reference to `std::ostream::operator<<(std::ostream& (*)(std::ostream&))'|
/usr/bin/ld: C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/vecpart.cpp|46|undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string()'|
/usr/bin/ld: C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/vecpart.cpp|47|undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string()'|
/usr/bin/ld: C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/vecpart.cpp|50|undefined reference to `std::basic_istream<char, std::char_traits<char> >& std::getline<char, std::char_traits<char>, std::allocator<char> >(std::basic_istream<char, std::char_traits<char> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)'|
/usr/bin/ld: C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/vecpart.cpp|50|undefined reference to `std::basic_ios<char, std::char_traits<char> >::operator bool() const'|
/usr/bin/ld: C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/vecpart.cpp|53|undefined reference to `std::__cxx11::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >::basic_stringstream(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::_Ios_Openmode)'|
/usr/bin/ld: C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/vecpart.cpp|56|undefined reference to `std::basic_istream<char, std::char_traits<char> >& std::getline<char, std::char_traits<char>, std::allocator<char> >(std::basic_istream<char, std::char_traits<char> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, char)'|
/usr/bin/ld: C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/vecpart.cpp|57|undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'|
/usr/bin/ld: C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/vecpart.cpp|57|undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'|
/usr/bin/ld: C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/vecpart.cpp|61|undefined reference to `std::basic_istream<char, std::char_traits<char> >& std::getline<char, std::char_traits<char>, std::allocator<char> >(std::basic_istream<char, std::char_traits<char> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, char)'|
/usr/bin/ld: C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/vecpart.cpp|67|undefined reference to `std::basic_istream<char, std::char_traits<char> >& std::getline<char, std::char_traits<char>, std::allocator<char> >(std::basic_istream<char, std::char_traits<char> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, char)'|
/usr/bin/ld: C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/vecpart.cpp|74|undefined reference to `std::basic_istream<char, std::char_traits<char> >& std::getline<char, std::char_traits<char>, std::allocator<char> >(std::basic_istream<char, std::char_traits<char> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, char)'|
/usr/bin/ld: C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/vecpart.cpp|81|undefined reference to `std::basic_istream<char, std::char_traits<char> >& std::getline<char, std::char_traits<char>, std::allocator<char> >(std::basic_istream<char, std::char_traits<char> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, char)'|
/usr/bin/ld: C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/C:/Users/uberl/Documents/Workspace/CodeBlocks/Bignumbers/vecpart.cpp|88|undefined reference to `std::basic_istream<char, std::char_traits<char> >& std::getline<char, std::char_traits<char>, std::allocator<char> >(std::basic_istream<char, std::char_traits<char> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, char)'|
||More errors follow but not being shown.|
||Edit the max errors limit in compiler options...|
||=== Build failed: 50 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 837
Re: Porting code - Windows to Linux
« Reply #3 on: September 28, 2021, 03:32:33 pm »
What happens if you click Rebuild?

Offline AndrewCot

  • Regular
  • ***
  • Posts: 250
Re: Porting code - Windows to Linux
« Reply #4 on: September 29, 2021, 02:02:13 am »
Check the project build settings (right click on the project and select the "Build Options" menu item) to check for references to your windows directories.
OR
In a text editor open the project file (projectname.cbp) and search for references to your windows directories.

Once you find the reference update it for Linux if applicable or remove it.

BTW: You may end up needing two project files, one for Linux and one for windows.

Offline Thunderchook

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: Porting code - Windows to Linux
« Reply #5 on: September 29, 2021, 11:50:16 am »
Okay, so I went back and hit "rebuild" and it didn't like it.
So, I hit F9 and (bizarrely) it ran!

Can't explain that one!

Thanks for your help!

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 837
Re: Porting code - Windows to Linux
« Reply #6 on: September 29, 2021, 12:05:45 pm »
Probably you copied also the object files, and this object files are not valid when changing host or compiler. You must force recompiling, and you can achieve this clicking on Rebuild or editing the source files (as you alreeady did).

Quote
If I copy the raw code back into files of the same name under the new operating system, it compiles up just fine.