furtherstep

we're on the road to next step.

  • Author

[GCC4.9][bug] warning: section “__textcoal_nt” is deprecate on Mac OSX Mojave

Posted by Seigfried on May 21, 2020
Posted in: Uncategorized. Leave a comment

When I compile c++ code by G++-4.9, I found some warnings as shown as follow,

/var/folders/z8/01n_7c6s4pbchqppl8cvbnk00000gn/T//ccgr3IWK.s:4:11: warning: section “__textcoal_nt” is deprecated

        .section __TEXT,__textcoal_nt,coalesced,pure_instructions

                 ^      ~~~~~~~~~~~~~

it’s a bug in old version of GCC.

The bug might be fix after GCC 5.X / 6.X, but 4.X.

Then I found only way to solve the bug is shown as follow,

g++-4.9 -o yourApplicationName yourCppName 2>&1 >/dev/null | grep -v -e ‘^/var/folders/*’ -e ‘^[[:space:]]*\.section’ -e ‘^[[:space:]]*\^[[:space:]]*~*’

The method is to filter the output of the compiler, and the G++4.9 can ignore the warnings. The program will compile well.

REF: 

1.warning: section “__textcoal_nt” is deprecate since updating to Mac OSX Sierra [duplicate]

2.[llvm] r250349 – [MachO] Stop generating *coal* sections.

3.Homebrew/homebrew-core#4812

4.Bug 71767 – Endless stream of warnings when using GCC with -Wa,-q and Clang Integrated Assembler

[c++][class][Primer 4/e]SalesItem.h practice

Posted by Seigfried on May 20, 2020
Posted in: Uncategorized. Leave a comment

The contents of “salesItem.h” is shown as follow,


#ifndef SALESITEM_H
#define SALESITEM_H

#include 

class salesItm
{

friend std::istream& operator>>(std::istream&, salesItm&);
friend std::ostream& operator *this; //using istream to read variable *this
}

public:
// operations on SalesItm objects
// for member binary operator: left-hand operand bound to implicit this pointer
salesItm& operator+=(const salesItm&);

double avgPrice() const;

bool sameIsbn(const salesItm &rhs) const {return isbn == rhs.isbn;}

salesItm(): unitsSold(0), revenue(0.0){}
private:
std::string isbn;
unsigned short unitsSold;
double revenue;

};

// nonmember binary operator: must declare a parameter for each operand
salesItm operator+(const salesItm&, const salesItm&);
double salesItm::avgPrice() const
{
if(unitsSold)
{
return revenue/unitsSold;
}
else
{
return 0;
}
}

inline
bool
operator==(const salesItm &lhs, const salesItm &rhs)
{
return lhs.unitsSold == rhs.unitsSold &&
lhs.revenue == rhs.revenue &&
lhs.sameIsbn(rhs);
}

inline
bool
operator!=(const salesItm &lhs, const salesItm &rhs)
{
return !(lhs == rhs);
}

// assumes that both objects refer to the same isbn
inline
salesItm&
salesItm::operator+=(const salesItm& rhs)
{
unitsSold += rhs.unitsSold;
revenue += rhs.revenue;
return *this;
}

// assumes that both objects refer to the same isbn
inline
salesItm
operator+(const salesItm& lhs, const salesItm& rhs)
{
salesItm ret(lhs); // copy lhs intoa local object that we'll return
ret += rhs; // add the ret(lhs) and rhs by overloaded operator +=
return ret; // return ret by value
}

using std::istream;
using std::ostream;

inline
istream&
operator>>(istream& in, salesItm& s)
{
double price;
in >> s.isbn >> s.unitsSold >> price;
if(in)
s.revenue = s.unitsSold * price;
else
s = salesItm();
return in;
}

inline
ostream&
operator<<(ostream& out, const salesItm& s)
{
out << s.isbn << "\t" << s.unitsSold << "\t" << s.revenue << "\t" << s.avgPrice();
return out;
}
#endif

The contents of cpp test file is shown as follow,


#include
#include "salesItem.h"
#include 

using namespace std;

int main()
{
//salesItm book1("0-201-7863");
//salesItm book2("0-201-7863");
//salesItm book2 = book1;

salesItm b1("0-201-7863", 10, 200.0);
salesItm b2("0-201-7863", 20, 370.0);
salesItm b3("0-201-7863", 50, 400.0);

b1 += b2;
salesItm b4 = b2 + b3;
cout << "b1 + b2 = " << b1 << endl;
cout << "b2 + b3 = " << b4 << endl;

//if (book1.sameIsbn(book2)):
//{
//cout << "The books are the same." << endl;
//cout << "the avg price of book1 = " << book1.avgPrice() << endl;
//cout << book1 << endl;
//cout << book2 << endl;
//}
//else
//cout << "The books are not the same." << endl;
//cout << book1 << endl;
//cout << book2 << endl;
return 0;

}

 

REF: C++ Primer, 4th Edition

[c++][debug]warning: control reaches end of non-void function

Posted by Seigfried on May 18, 2020
Posted in: Uncategorized. Leave a comment

warning: control reaches end of non-void function

I create a non-void function but forget to return at the end of function.

for example, overloaded Operator


istream&

operator >> (istream& in, const classType & s)

{

return in; // The function need to return in, becuz it's non-void function.

}

 

REF:[C語言] 編譯報錯warning: control reaches end of non-void function

[iOS][issue] compilation terminated with GCC 4.9 on Mojave 10.14

Posted by Seigfried on May 15, 2020
Posted in: Uncategorized. Leave a comment

The default GCC version of my MacBook pro is 4.2.1.After I install the GCC 4.9,  I can’t use it to compile my code. The error message shows as below,

fatal error: stdio.h: No such file or directory.

#include <stdio.h>

~~~~~~~~~

compilation terminated

After lots search and test, I found a solution to solve this problem on Stackoverflow.Open and Install the following file, and it’s done.

/Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg

 

REF:

  1. https://stackoverflow.com/questions/52509602/cant-compile-c-program-on-a-mac-after-upgrade-to-mojave#
  2. https://developer.apple.com/documentation/xcode_release_notes/xcode_10_release_notes

[iOS][Git] How to edit gitconfig by Vim in Terminal /如何在終端機使用編輯器(Vim)修改gitconfig

Posted by Seigfried on April 28, 2020
Posted in: Uncategorized. Leave a comment
  1. 在應用程式夾(Application Folder)裡面找工具程式夾(Tools Folder),工具程式夾裡面有終端機(Terminal)
  2. 在終端機內輸入以下程式碼使用編輯器Vi/Vim打開gitconfig進行檔案編修
vi ~/.gitconfig

vim ~/.gitconfig

檔案應會顯示以下訊息(The file will show you the following information if you install git already.)

[user]
        name = username
        email = username@address
[core]
        excludesfile = /Users/username/.gitignore_global
[difftool "sourcetree"]
        cmd = opendiff \"$LOCAL\" \"$REMOTE\"
        path =
[commit]
        template = /Users/username/.stCommitMsg

Posts navigation

← Older Entries
  • Recent Posts

    • [GCC4.9][bug] warning: section “__textcoal_nt” is deprecate on Mac OSX Mojave
    • [c++][class][Primer 4/e]SalesItem.h practice
    • [c++][debug]warning: control reaches end of non-void function
    • [iOS][issue] compilation terminated with GCC 4.9 on Mojave 10.14
    • [iOS][Git] How to edit gitconfig by Vim in Terminal /如何在終端機使用編輯器(Vim)修改gitconfig
  • Recent Comments

    Seigfried's avatarSeigfried on [OpenCV] 取得灰階圖的灰階值
    Seigfried's avatarSeigfried on [OpenCV] 使用imread函數讀圖轉成灰階圖
    Seigfried's avatarSeigfried on [OpenCV] 使用imread函數讀圖轉成灰階圖
    Seigfried's avatarSeigfried on [OpenCV] 取得灰階圖的灰階值
    Seigfried's avatarSeigfried on [OpenCV] 取得灰階圖的灰階值
  • Archives

    • May 2020
    • April 2020
    • September 2017
    • August 2016
    • December 2015
    • November 2015
    • September 2015
    • August 2015
    • July 2015
    • April 2015
    • June 2014
    • April 2014
    • March 2014
  • Categories

    • Android
    • C++
    • Fortran
    • OpenCV
    • OpenCV4Android
    • OpenGL
    • software
    • Uncategorized
    • wordpress
  • Meta

    • Create account
    • Log in
    • Entries feed
    • Comments feed
    • WordPress.com
Create a free website or blog at WordPress.com.
furtherstep
Blog at WordPress.com.
  • Subscribe Subscribed
    furtherstep

    Have a WordPress.com account? Log in now.

  • furtherstep
    View site in Reader
    Manage subscriptionsSign upLog in
    Report this content
    Collapse this bar
Loading Comments...
Create your own website, free on WordPress.com.Create your own website.
Start free