Tag Archives: int

[Solved] undefined reference to `cv::imread(std::string const&, int)’

problem

Error message: undefined reference to ` CV:: imread (STD:: String const & amp;, int) ‘

When the above error occurs, I thought there was a problem with the opencv link, so I have been trying to solve the problem of importing opencv and trying to link the library in various ways, but the error will always appear in the end

Finally, it was found that the problem was C + + abi

Solution

In the code #define_GLIBCXX_USE_CXX11_ABI 0 causes this error. If it is removed, it can run normally

reason

#define _GLIBCXX_USE_CXX11_ABI 0 is an old version of ABI used when compiling links

In libstdc + + (c + + standard library under GCC) released in GCC version 5.1, a new implementation of STD:: basic_string is added. The new implementation coexists with the old implementation, but has different names. The new implementation is called STD:: _cxx11:: basic_string, and the old one is called STD:: basic_string.

The newer version of GCC will compile STD:: string as STD:: string in C + + 11:__cxx11::basic_string< char> At this time, if the third-party library you call does not enable the C + + 11 feature during compilation, the STD:: string in it is actually STD:: basic_string< char>, The two cannot be converted to each other# define _GLIBCXX_USE_CXX11_ABI 0 is to make STD:: string in your code compile according to the old implementation

But my opencv should have been compiled with STD:: basic_ String, so it doesn’t need to be set. If it is set, the error shown in the title will appear instead

However, if the third-party library uses an old implementation and its compiler is a new version, you need to add #define_GLIBCXX_USE_CXX11_ ABI 0, otherwise undefined reference to ` CV:: imread (STD:: _cxx11:: basic_string <char, STD:: char_traits, STD:: allocator > const & int) ‘will appear

 

Solve Python MySQL insert int data error: typeerror% d format: a number is required, not str

Today, when using Python to crawl data and write it to MySQL database, the following statement is used:

       cursor.execute(
                    "insert into comments_p_spider(owner_id,from_name,content,create_time,score,comment_level) values(%d,%s,%s,%s,%f,%s)",
                    (p_id,str(username), str(contentStr), str(create_time),float(score), str(comment_level)))
            conn.commit()

  

The error is as follows:

TypeError: %d format: a number is required, not str

Solution: the format string is not really a normal Python format string. You must always use% sfor all fields

That is to say, the string format of mysqldb is not the standard Python string format, and% s should always be used for string format

So change the value format of the SQL statement of the code to% s (no matter what type of data you want to insert), and it will run normally

        cursor.execute(
                    "insert into comments_p_spider(owner_id,from_name,content,create_time,score,comment_level) values(%s,%s,%s,%s,%s,%s)",
                    (p_id,str(username), str(contentStr), str(create_time),float(score), str(comment_level)))
            conn.commit()