Xcode添加新库

时间:2018-08-28 15:54:39

标签: c++ xcode

我遇到了一个我无法解决的问题。问题是我正在尝试向xcode添加新库,而以前从未这样做过。如果问题与库有关,或者我向xcode添加新库,我现在不是真的。 我试图添加的库是tidylib(tidy-html5)。

#include <tidy.h>
#include <tidybuffio.h>
#include <stdio.h>
#include <errno.h>


int main(int argc, char **argv )
{
    const char* input = "<title>Foo</title><p>Foo!";
    TidyBuffer output = {0};
    TidyBuffer errbuf = {0};
    int rc = -1;
    Bool ok;

    TidyDoc tdoc = tidyCreate();                     // Initialize "document"
    printf( "Tidying:\t%s\n", input );

    ok = tidyOptSetBool( tdoc, TidyXhtmlOut, yes );  // Convert to XHTML
    if ( ok )
        rc = tidySetErrorBuffer( tdoc, &errbuf );      // Capture diagnostics
    if ( rc >= 0 )
        rc = tidyParseString( tdoc, input );           // Parse the input
    if ( rc >= 0 )
        rc = tidyCleanAndRepair( tdoc );               // Tidy it up!
    if ( rc >= 0 )
        rc = tidyRunDiagnostics( tdoc );               // Kvetch
    if ( rc > 1 )                                    // If error, force output.
        rc = ( tidyOptSetBool(tdoc, TidyForceOutput, yes) ? rc : -1 );
    if ( rc >= 0 )
        rc = tidySaveBuffer( tdoc, &output );          // Pretty Print

    if ( rc >= 0 )
    {
        if ( rc > 0 )
            printf( "\nDiagnostics:\n\n%s", errbuf.bp );
        printf( "\nAnd here is the result:\n\n%s", output.bp );
    }
    else
        printf( "A severe error (%d) occurred.\n", rc );

    tidyBufFree( &output );
    tidyBufFree( &errbuf );
    tidyRelease( tdoc );
    return rc;
}

我的问题是我一直都遇到以下错误,但无法修复:

Undefined symbols for architecture x86_64:
"_tidyBufFree", referenced from:
_main in main.o
"_tidyCleanAndRepair", referenced from:
_main in main.o
"_tidyCreate", referenced from:
_main in main.o
"_tidyOptSetBool", referenced from:
_main in main.o
"_tidyParseString", referenced from:
_main in main.o
"_tidyRelease", referenced from:
_main in main.o
"_tidyRunDiagnostics", referenced from:
_main in main.o
"_tidySaveBuffer", referenced from:
_main in main.o
"_tidySetErrorBuffer", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
     

我做了什么?

I set up the header search path to "/usr/local/Cellar/tidy-html5/5.6.0/include/"
I set up the library search path to "/usr/local/Cellar/tidy-html5/5.6.0/lib/"
I also tried to set other link flags to "-ltidylib"

系统?

  • MacOS High Sierra 10.13.4

  • XCode 9.4.1

解决方案 您必须在其他“其他链接器”标志下使用“ -ltidy”而不是“ -ltidylib”

1 个答案:

答案 0 :(得分:0)

选择目标(通常是您正在构建的应用程序),然后单击“构建阶段”选项卡。构建阶段是构建所需的不同步骤,例如检查依赖项,编译,复制资源等。其中一个是“使用库链接二进制文件”,它包括项目应链接的库和框架的列表。单击+按钮以将新项目添加到列表中,然后选择要添加的库。然后构建。